summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-07 20:34:08 -0500
committerJeff Carr <[email protected]>2025-09-07 21:41:26 -0500
commita099bbd3e656ac2d0cf1db656f08d91c673db437 (patch)
tree43a5c6e3902d85a73ecc5cadba281c6dafaa0b8c
parentc2e0e8e80b5831996da38efbfaa4bb206875bf40 (diff)
add support for old version of the tool using new code
-rw-r--r--Makefile2
-rw-r--r--doList.go17
-rw-r--r--handlePatches.go16
-rw-r--r--http.go22
4 files changed, 42 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 60ef21f..d46394f 100644
--- a/Makefile
+++ b/Makefile
@@ -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 \
diff --git a/doList.go b/doList.go
index 382c083..09068cc 100644
--- a/doList.go
+++ b/doList.go
@@ -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
diff --git a/http.go b/http.go
index 99f02d2..0714758 100644
--- a/http.go
+++ b/http.go
@@ -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
}