summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-07 19:14:38 -0500
committerJeff Carr <[email protected]>2025-09-07 21:41:20 -0500
commitecf404994754b339e6e3fce1fceda7f0e0734d7c (patch)
tree8928eb7b9d94ba02ac11a3f10226d6575392d7ab
parente3c8669be446ec3529ea924ccd0034cd44dae170 (diff)
start using a standard http PB
-rw-r--r--patchset.Get.go4
-rw-r--r--patchset.Send.go3
-rw-r--r--patchset.config.go52
-rw-r--r--patchset.http.go30
4 files changed, 67 insertions, 22 deletions
diff --git a/patchset.Get.go b/patchset.Get.go
index 5780fab..e9f183d 100644
--- a/patchset.Get.go
+++ b/patchset.Get.go
@@ -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
diff --git a/patchset.Send.go b/patchset.Send.go
index ab79718..eaac09e 100644
--- a/patchset.Send.go
+++ b/patchset.Send.go
@@ -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
}
diff --git a/patchset.config.go b/patchset.config.go
index 4a27726..fd9b509 100644
--- a/patchset.config.go
+++ b/patchset.config.go
@@ -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
diff --git a/patchset.http.go b/patchset.http.go
index 63b73b1..5e33a6f 100644
--- a/patchset.http.go
+++ b/patchset.http.go
@@ -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)