76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"go.wit.com/lib/protobuf/forgepb"
|
|
"go.wit.com/lib/protobuf/gitpb"
|
|
"go.wit.com/lib/protobuf/httppb"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
func addNewPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches {
|
|
newPatchesPB := new(forgepb.Patches)
|
|
for newpatch := range pb.IterAll() {
|
|
me.forge.AddNewPatch(newpatch)
|
|
newPatchesPB.Append(newpatch)
|
|
}
|
|
return newPatchesPB
|
|
}
|
|
|
|
func sendPendingPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches {
|
|
allPatchesPB := new(forgepb.Patches)
|
|
for pset := range me.forge.Patchsets.IterAll() {
|
|
for newpatch := range pset.Patches.IterAll() {
|
|
allPatchesPB.Append(newpatch)
|
|
}
|
|
}
|
|
return allPatchesPB
|
|
}
|
|
|
|
func handlePatches(w http.ResponseWriter, pb *forgepb.Patches) error {
|
|
route := pb.HttpRequest.Route
|
|
|
|
log.Info("GOT PATCHES ROUTE", route, "with # patches =", pb.Len())
|
|
if strings.HasPrefix(route, "/patches/old") {
|
|
} else if strings.HasPrefix(route, "/patches/new") {
|
|
log.Info("add new patches")
|
|
} else {
|
|
log.Info("unknown route", route)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func makeReposPB(reqPB *httppb.HttpRequest) (*gitpb.Repos, error) {
|
|
pb := gitpb.NewRepos()
|
|
err := pb.Unmarshal(reqPB.Body)
|
|
return pb, err
|
|
}
|
|
|
|
func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) {
|
|
pb := forgepb.NewPatches()
|
|
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
|
|
}
|
|
|
|
func marshalPatchesPB(r *http.Request, msg []byte) (*forgepb.Patches, error) {
|
|
pb := forgepb.NewPatches()
|
|
|
|
if err := pb.Unmarshal(msg); err != nil {
|
|
log.Info("proto.Unmarshal() failed on wire message len", len(msg), err)
|
|
// add the header
|
|
pb.AddHttpToPB(r)
|
|
return pb, err
|
|
}
|
|
// add the header
|
|
pb.AddHttpToPB(r)
|
|
return pb, nil
|
|
}
|