start using a standard http PB
This commit is contained in:
parent
e3c8669be4
commit
ecf4049947
|
@ -66,11 +66,11 @@ func (f *Forge) loadUpstreamPatchsets(psets *Patchsets) {
|
||||||
// log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace)
|
// log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := f.addRandomPatch(patch); err == nil {
|
if f.AddNewPatch(patch) {
|
||||||
log.Info("\tnew patch added:", patch.CommitHash, found.Name, found.Comment, author)
|
log.Info("\tnew patch added:", patch.CommitHash, found.Name, found.Comment, author)
|
||||||
foundnew = true
|
foundnew = true
|
||||||
} else {
|
} 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
|
pset.State = found.State
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/lib/protobuf/httppb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ func (f *Forge) SendPatches(what string, p *Patches) (*Patches, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Infof("pb: len=%d, err=%v\n", len(data), 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,20 @@ func (pb *Patchset) ShowPatchsets() error {
|
||||||
return nil
|
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
|
// adds a patchset or just the patches
|
||||||
func (f *Forge) AddPatchset(pb *Patchset) bool {
|
func (f *Forge) AddPatchset(pb *Patchset) bool {
|
||||||
var changed bool
|
var changed bool
|
||||||
|
@ -111,11 +125,11 @@ func (f *Forge) AddPatchset(pb *Patchset) bool {
|
||||||
if f.findPatch(patch) {
|
if f.findPatch(patch) {
|
||||||
// log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace)
|
// log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace)
|
||||||
} else {
|
} else {
|
||||||
if err := f.addRandomPatch(patch); err == nil {
|
if f.AddNewPatch(patch) {
|
||||||
log.Info("\tnew patch added:", patch.CommitHash, pb.Name, pb.Comment, author)
|
log.Info("\tnew patch added:", patch.CommitHash, pb.Name, pb.Comment, author)
|
||||||
changed = true
|
changed = true
|
||||||
} else {
|
} 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
|
var fauto *Patchset
|
||||||
log.Warn("findAutoPatchset() had to create 'forge auto commit'")
|
log.Warn("findAutoPatchset() had to create 'forge auto commit'")
|
||||||
if fauto == nil {
|
if fauto == nil {
|
||||||
fauto = new(Patchset)
|
fauto = makeDefaultPatchset()
|
||||||
fauto.Name = "forge auto commit"
|
f.Patchsets.Append(fauto)
|
||||||
fauto.Patches = NewPatches()
|
|
||||||
fauto.Uuid = uuid.New().String()
|
|
||||||
f.Patchsets.Patchsets = append(f.Patchsets.Patchsets, fauto)
|
|
||||||
}
|
}
|
||||||
return fauto
|
return fauto
|
||||||
}
|
}
|
||||||
|
|
||||||
// adds submitted patches not specifically assigned to a patchset
|
func makeDefaultPatchset() *Patchset {
|
||||||
// to the generic patchset called "forge auto commit"
|
fauto := new(Patchset)
|
||||||
func (f *Forge) addRandomPatch(patch *Patch) error {
|
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
|
// ignore patch if it's already here
|
||||||
if f.findPatch(patch) {
|
if f.findPatch(patch) {
|
||||||
log.Info("already found patch", patch.CommitHash, patch.Namespace)
|
log.Info("already found patch", patch.CommitHash, patch.Namespace)
|
||||||
return nil
|
return false
|
||||||
}
|
}
|
||||||
fauto := f.findAutoPatchset()
|
fauto := f.findAutoPatchset()
|
||||||
if fauto == nil {
|
if fauto == nil {
|
||||||
return log.Errorf("no default place yet")
|
// should have made the default patchset
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
newpb := proto.Clone(patch).(*Patch)
|
fauto.Patches.Append(patch)
|
||||||
if newpb == nil {
|
return true
|
||||||
return log.Errorf("proto.Clone returned nil")
|
|
||||||
}
|
|
||||||
fauto.Patches.Patches = append(fauto.Patches.Patches, newpb)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if the patch already exists in the protobuf
|
// returns true if the patch already exists in the protobuf
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
|
||||||
|
"go.wit.com/lib/protobuf/httppb"
|
||||||
"go.wit.com/log"
|
"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) {
|
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.
|
// if you ever have "http://www.wit.com//" GO will regect the server recieving it.
|
||||||
// Even though the linux kernel gets the network payload
|
// 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
|
// 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()
|
newpb := NewPatches()
|
||||||
err = newpb.Unmarshal(newdata)
|
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
|
return newpb, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +93,22 @@ func (p *Patchset) HttpPost(baseURL string, route string) (*Patchset, error) {
|
||||||
return newpb, err
|
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) {
|
func (p *Patchsets) HttpPostVerbose(baseURL string, route string) (*Patchsets, error) {
|
||||||
p.PrintTable()
|
p.PrintTable()
|
||||||
return p.HttpPost(baseURL, route)
|
return p.HttpPost(baseURL, route)
|
||||||
|
|
Loading…
Reference in New Issue