add "/applied" and "/merged" routes

This commit is contained in:
Jeff Carr 2025-09-07 22:47:26 -05:00
parent 873cb39932
commit 5e71dd3ecc
3 changed files with 34 additions and 0 deletions

View File

@ -34,3 +34,20 @@ func findPatch(newpatch *forgepb.Patch) bool {
return false return false
} }
// returns true if the patch already exists in the protobuf
func expirePatch(newpatch *forgepb.Patch) bool {
// log.Info("\tlook for patch:", newpatch.CommitHash, newpatch.Namespace)
for pset := range me.forge.Patchsets.IterAll() {
for _, patch := range pset.Patches.Patches {
if patch.CommitHash == newpatch.CommitHash {
patch.NewHash = newpatch.NewHash
// log.Info("\tfound pset!!!!!!", pset.Uuid, patch.Namespace)
return true
}
}
}
return false
}

View File

@ -19,6 +19,16 @@ func addNewPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patc
return newPatchesPB return newPatchesPB
} }
func handleMergedPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches {
newPatchesPB := new(forgepb.Patches)
for newpatch := range pb.IterAll() {
if expirePatch(newpatch) {
newPatchesPB.Append(newpatch)
}
}
return newPatchesPB
}
func sendPendingPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches { func sendPendingPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches {
allPatchesPB := new(forgepb.Patches) allPatchesPB := new(forgepb.Patches)
for pset := range me.forge.Patchsets.IterAll() { for pset := range me.forge.Patchsets.IterAll() {

View File

@ -114,6 +114,13 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
case "/patches/new": case "/patches/new":
result = addNewPatches(pb, reqPB) result = addNewPatches(pb, reqPB)
log.Infof("addNewPatches() pb.Len()=%d result.Len()=%d\n", pb.Len(), result.Len()) log.Infof("addNewPatches() pb.Len()=%d result.Len()=%d\n", pb.Len(), result.Len())
case "/patches/applied":
log.Info("not really anything needs to be done on applied patches?")
// result = handleAppliedPatches(pb, reqPB)
case "/patches/merged":
log.Info("a maintainer has merged these patches")
result = handleMergedPatches(pb, reqPB)
// result = handleAppliedPatches(pb, reqPB)
case "/patches/get": case "/patches/get":
result = sendPendingPatches(pb, reqPB) result = sendPendingPatches(pb, reqPB)
default: default: