start using a standard http PB

This commit is contained in:
Jeff Carr 2025-09-07 19:14:38 -05:00
parent e3c8669be4
commit ecf4049947
4 changed files with 67 additions and 22 deletions

View File

@ -66,11 +66,11 @@ func (f *Forge) loadUpstreamPatchsets(psets *Patchsets) {
// log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace)
continue
}
if err := f.addRandomPatch(patch); err == nil {
if f.AddNewPatch(patch) {
log.Info("\tnew patch added:", patch.CommitHash, found.Name, found.Comment, author)
foundnew = true
} else {
log.Info("\tnew patch failed:", patch.CommitHash, found.Name, found.Comment, author, err)
log.Info("\tnew patch failed:", patch.CommitHash, found.Name, found.Comment, author)
}
}
pset.State = found.State

View File

@ -8,6 +8,7 @@ import (
"strings"
"time"
"go.wit.com/lib/protobuf/httppb"
"go.wit.com/log"
)
@ -18,7 +19,7 @@ func (f *Forge) SendPatches(what string, p *Patches) (*Patches, error) {
return nil, err
}
log.Infof("pb: len=%d, err=%v\n", len(data), err)
newdata, err := f.HttpPost("rm this", route, data)
newdata, err := httppb.HttpPost("rm this", route, data)
if err != nil {
return nil, err
}

View File

@ -96,6 +96,20 @@ func (pb *Patchset) ShowPatchsets() error {
return nil
}
// adds a patch. returns true if patch is new
func (f *Forge) AddPatch(patch *Patch) bool {
if f.findPatch(patch) {
// log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace)
return false
}
if f.AddNewPatch(patch) {
log.Info("\tnew patch added:", patch.CommitHash, patch.Gs, patch.Gae, patch.Gan)
return true
}
log.Info("\tnew patch failed:", patch.CommitHash, patch.Gs)
return false
}
// adds a patchset or just the patches
func (f *Forge) AddPatchset(pb *Patchset) bool {
var changed bool
@ -111,11 +125,11 @@ func (f *Forge) AddPatchset(pb *Patchset) bool {
if f.findPatch(patch) {
// log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace)
} else {
if err := f.addRandomPatch(patch); err == nil {
if f.AddNewPatch(patch) {
log.Info("\tnew patch added:", patch.CommitHash, pb.Name, pb.Comment, author)
changed = true
} else {
log.Info("\tnew patch failed:", patch.CommitHash, pb.Name, pb.Comment, author, err)
log.Info("\tnew patch failed:", patch.CommitHash, pb.Name, pb.Comment, author)
}
}
@ -153,33 +167,35 @@ func (f *Forge) findAutoPatchset() *Patchset {
var fauto *Patchset
log.Warn("findAutoPatchset() had to create 'forge auto commit'")
if fauto == nil {
fauto = new(Patchset)
fauto.Name = "forge auto commit"
fauto.Patches = NewPatches()
fauto.Uuid = uuid.New().String()
f.Patchsets.Patchsets = append(f.Patchsets.Patchsets, fauto)
fauto = makeDefaultPatchset()
f.Patchsets.Append(fauto)
}
return fauto
}
// adds submitted patches not specifically assigned to a patchset
// to the generic patchset called "forge auto commit"
func (f *Forge) addRandomPatch(patch *Patch) error {
func makeDefaultPatchset() *Patchset {
fauto := new(Patchset)
fauto.Name = "forge auto commit"
fauto.Patches = NewPatches()
fauto.Uuid = uuid.New().String()
return fauto
}
// adds submitted patches not
// If the patch was actually new, return true
func (f *Forge) AddNewPatch(patch *Patch) bool {
// ignore patch if it's already here
if f.findPatch(patch) {
log.Info("already found patch", patch.CommitHash, patch.Namespace)
return nil
return false
}
fauto := f.findAutoPatchset()
if fauto == nil {
return log.Errorf("no default place yet")
// should have made the default patchset
return false
}
newpb := proto.Clone(patch).(*Patch)
if newpb == nil {
return log.Errorf("proto.Clone returned nil")
}
fauto.Patches.Patches = append(fauto.Patches.Patches, newpb)
return nil
fauto.Patches.Append(patch)
return true
}
// returns true if the patch already exists in the protobuf

View File

@ -9,6 +9,7 @@ import (
"os"
"os/user"
"go.wit.com/lib/protobuf/httppb"
"go.wit.com/log"
)
@ -18,6 +19,10 @@ func (p *Patches) HttpPostVerbose(baseURL string, route string) (*Patches, error
}
func (p *Patches) HttpPost(baseURL string, route string) (*Patches, error) {
if p == nil {
log.Info("can't post a nil PB")
return nil, log.Errorf("can't post a nil PB")
}
// if you ever have "http://www.wit.com//" GO will regect the server recieving it.
// Even though the linux kernel gets the network payload
// also it never gives you an error about that, it just goes away invisably inside GO
@ -45,7 +50,14 @@ func (p *Patches) HttpPost(baseURL string, route string) (*Patches, error) {
newpb := NewPatches()
err = newpb.Unmarshal(newdata)
log.Infof("patchset PB HttpPost %s sent len(%d) got len(%d)\n", finalURL.String(), p.Len(), newpb.Len())
if newpb == nil {
log.Info("HttpPost() newpb WAS NIL")
}
if err != nil {
log.Info("HttpPost() err =", err)
} else {
log.Infof("patchset PB HttpPost %s sent len(%d) got len(%d)\n", finalURL.String(), p.Len(), newpb.Len())
}
return newpb, err
}
@ -81,6 +93,22 @@ func (p *Patchset) HttpPost(baseURL string, route string) (*Patchset, error) {
return newpb, err
}
func (p *Patches) SendReply(w http.ResponseWriter, reqPB *httppb.HttpRequest) error {
data, err := p.Marshal()
if err != nil {
reqPB.Errors = append(reqPB.Errors, log.Sprintf("%v", err))
}
if len(data) == 0 {
reqPB.Errors = append(reqPB.Errors, "Patches PB data was nil/emtpy without Marsha() error")
return nil
}
i, err := w.Write(data)
if err != nil {
reqPB.Errors = append(reqPB.Errors, log.Sprintf("i=%d %v", i, err))
}
return err
}
func (p *Patchsets) HttpPostVerbose(baseURL string, route string) (*Patchsets, error) {
p.PrintTable()
return p.HttpPost(baseURL, route)