diff options
| author | Jeff Carr <[email protected]> | 2025-09-07 20:34:08 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-07 21:41:26 -0500 |
| commit | a099bbd3e656ac2d0cf1db656f08d91c673db437 (patch) | |
| tree | 43a5c6e3902d85a73ecc5cadba281c6dafaa0b8c | |
| parent | c2e0e8e80b5831996da38efbfaa4bb206875bf40 (diff) | |
add support for old version of the tool using new code
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | doList.go | 17 | ||||
| -rw-r--r-- | handlePatches.go | 16 | ||||
| -rw-r--r-- | http.go | 22 |
4 files changed, 42 insertions, 15 deletions
@@ -4,7 +4,7 @@ VERSION = $(shell git describe --tags) BUILDTIME = $(shell date +%Y.%m.%d_%H%M) all: build-verbose - # ./forged merge + ./forged list build: goimports GO111MODULE=off go build \ @@ -8,23 +8,12 @@ import ( func doList() error { log.Info("do list here") - if err := me.forge.LoadPatchsets(); err != nil { - badExit(err) - } - - // first show the general patchset protobuf - for pb := range me.forge.Patchsets.IterAll() { - if pb.Name == "forge auto commit" { - pb.ShowPatchsets() - } - } - // show all the patchsets with Names for pset := range me.forge.Patchsets.IterAll() { - if pset.Name == "forge auto commit" { - continue + log.Info("Info", pset.Name, pset.Uuid) + for i, patch := range pset.Patches.Patches { + log.Info("\t", i, patch.CommitHash, patch.Namespace) } - pset.ShowPatchsets() } return nil } diff --git a/handlePatches.go b/handlePatches.go index 5d07924..4265e55 100644 --- a/handlePatches.go +++ b/handlePatches.go @@ -29,6 +29,16 @@ func sendPendingPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb return allPatchesPB } +func sendPendingPatchsets(pb *forgepb.Patchsets, reqPB *httppb.HttpRequest) *forgepb.Patchsets { + allPatchsetsPB := new(forgepb.Patchsets) + for pset := range me.forge.Patchsets.IterAll() { + if pset.Name == "forge auto submit" { + allPatchsetsPB.Append(pset) + } + } + return allPatchsetsPB +} + func handlePatches(w http.ResponseWriter, pb *forgepb.Patches) error { route := pb.HttpRequest.Route @@ -55,6 +65,12 @@ func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) { return pb, err } +func makePatchsetsPB(reqPB *httppb.HttpRequest) (*forgepb.Patchsets, error) { + pb := forgepb.NewPatchsets() + err := pb.Unmarshal(reqPB.Body) + return pb, err +} + func sendPatchesError(w http.ResponseWriter, r *forgepb.Patches, err error) error { log.Info("send error back to user", err) return nil @@ -95,6 +95,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { // todo: logReq(reqPB) return } + if strings.HasPrefix(route, "/patches/") { pb, err := makePatchesPB(reqPB) if err != nil { @@ -113,6 +114,27 @@ func okHandler(w http.ResponseWriter, r *http.Request) { if err := result.SendReply(w, reqPB); err != nil { log.Info("Oh well, Send to client failed. err =", err) } + me.forge.SavePatchsets() + // todo: logReq(reqPB) + return + } + + if strings.HasPrefix(route, "/patchsets/") { + pb, err := makePatchsetsPB(reqPB) + if err != nil { + reqPB.Errors = append(reqPB.Errors, log.Sprintf("%v", err)) + } + result := forgepb.NewPatchsets() + switch route { + case "/patches/get": + result = sendPendingPatchsets(pb, reqPB) + default: + result = sendPendingPatchsets(pb, reqPB) + } + if err := result.SendReply(w, reqPB); err != nil { + log.Info("Oh well, Send to client failed. err =", err) + } + me.forge.SavePatchsets() // todo: logReq(reqPB) return } |
