http post a patch set
This commit is contained in:
parent
a11c4f46bd
commit
268e05f108
3
Makefile
3
Makefile
|
@ -60,3 +60,6 @@ gui: install
|
|||
|
||||
patches: install
|
||||
forge --do-patches
|
||||
|
||||
patches-localhost: install
|
||||
forge --do-patches --url "http://localhost:2233/"
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
Additional IP Rights Grant (Patents)
|
||||
|
||||
"This implementation" means the copyrightable works distributed by
|
||||
WIT.COM Inc. as part of the go.wit.com project.
|
||||
|
||||
WIT.COM Inc. hereby grants to You a perpetual, worldwide, non-exclusive,
|
||||
no-charge, royalty-free, irrevocable (except as stated in this section)
|
||||
patent license to make, have made, use, offer to sell, sell, import,
|
||||
transfer and otherwise run, modify and propagate the contents of this
|
||||
implementation on go.wit.com, where such license applies only to those patent
|
||||
claims, both currently owned or controlled by WIT.COM Inc. and acquired in
|
||||
the future, licensable by WIT.COM Inc. that are necessarily infringed by this
|
||||
implementation on go.wit.com. This grant does not include claims that would be
|
||||
infringed only as a consequence of further modification of this
|
||||
implementation. If you or your agent or exclusive licensee institute or
|
||||
order or agree to the institution of patent litigation against any
|
||||
entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
||||
that this implementation on go.wit.com or any code incorporated within this
|
||||
implementation on go.wit.com constitutes direct or contributory patent
|
||||
infringement, or inducement of patent infringement, then any patent
|
||||
rights granted to you under this License for this implementation on go.wit.com
|
||||
shall terminate as of the date such litigation is filed.
|
39
argv.go
39
argv.go
|
@ -7,25 +7,26 @@ package main
|
|||
var argv args
|
||||
|
||||
type args struct {
|
||||
Config bool `arg:"--config" help:"work from your .config/forge/ configuration"`
|
||||
FindAll bool `arg:"--find-all" help:"select every repo"`
|
||||
FindReadOnly bool `arg:"--find-readonly" help:"include read-only repos"`
|
||||
FindMine bool `arg:"--find-mine" help:"download private and writeable repos"`
|
||||
FindFavorites bool `arg:"--find-favorites" help:"download repos marked as favorites"`
|
||||
FindPrivate bool `arg:"--find-private" help:"list private repos in .config/forge/"`
|
||||
DoList bool `arg:"--do-list" help:"list found repos"`
|
||||
DoScan bool `arg:"--do-scan" help:"rescan your repos"`
|
||||
DoClone bool `arg:"--do-clone" help:"go-clone things you are missing"`
|
||||
DoForce bool `arg:"--do-force" help:"force redo go-clone"`
|
||||
DoGitPull bool `arg:"--do-git-pull" help:"run 'git pull' on all your repos"`
|
||||
DoGitReset bool `arg:"--do-git-reset" help:"run 'git reset --hard' on all read-only repos"`
|
||||
DoBuild bool `arg:"--do-build" default:"true" help:"also try to build it"`
|
||||
DoInstall bool `arg:"--do-install" help:"try to install every binary package"`
|
||||
DoRedoGoMod bool `arg:"--do-RedoGoMod" help:"remake all the go.sum and go.mod files"`
|
||||
DoPatchSet bool `arg:"--do-patches" help:"make patch set"`
|
||||
DoGui bool `arg:"--do-gui" help:"test the gui"`
|
||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
||||
Fix bool `arg:"--fix" help:"fix config, save config & exit"`
|
||||
Config bool `arg:"--config" help:"work from your .config/forge/ configuration"`
|
||||
FindAll bool `arg:"--find-all" help:"select every repo"`
|
||||
FindReadOnly bool `arg:"--find-readonly" help:"include read-only repos"`
|
||||
FindMine bool `arg:"--find-mine" help:"download private and writeable repos"`
|
||||
FindFavorites bool `arg:"--find-favorites" help:"download repos marked as favorites"`
|
||||
FindPrivate bool `arg:"--find-private" help:"list private repos in .config/forge/"`
|
||||
DoList bool `arg:"--do-list" help:"list found repos"`
|
||||
DoScan bool `arg:"--do-scan" help:"rescan your repos"`
|
||||
DoClone bool `arg:"--do-clone" help:"go-clone things you are missing"`
|
||||
DoForce bool `arg:"--do-force" help:"force redo go-clone"`
|
||||
DoGitPull bool `arg:"--do-git-pull" help:"run 'git pull' on all your repos"`
|
||||
DoGitReset bool `arg:"--do-git-reset" help:"run 'git reset --hard' on all read-only repos"`
|
||||
DoBuild bool `arg:"--do-build" default:"true" help:"also try to build it"`
|
||||
DoInstall bool `arg:"--do-install" help:"try to install every binary package"`
|
||||
DoRedoGoMod bool `arg:"--do-RedoGoMod" help:"remake all the go.sum and go.mod files"`
|
||||
DoPatchSet bool `arg:"--do-patches" help:"make patch set"`
|
||||
DoGui bool `arg:"--do-gui" help:"test the gui"`
|
||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
||||
Fix bool `arg:"--fix" help:"fix config, save config & exit"`
|
||||
URL string `arg:"--url" default:"http://go.wit.com/" help:"base url"`
|
||||
}
|
||||
|
||||
func (args) Version() string {
|
||||
|
|
35
main.go
35
main.go
|
@ -4,6 +4,7 @@ package main
|
|||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
|
@ -21,6 +22,8 @@ var configSave bool
|
|||
func main() {
|
||||
me = new(mainType)
|
||||
me.pp = arg.MustParse(&argv)
|
||||
me.urlbase = argv.URL
|
||||
me.urlbase = strings.Trim(me.urlbase, "/") // track down why trailing '/' makes http POST not work
|
||||
|
||||
// load the ~/.config/forge/ config
|
||||
me.forge = forgepb.Init()
|
||||
|
@ -87,35 +90,3 @@ func main() {
|
|||
doCobol()
|
||||
}
|
||||
}
|
||||
|
||||
func sendDevelDiff() {
|
||||
pset, err := me.forge.MakeDevelPatchSet()
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
all := pset.SortByFilename()
|
||||
for all.Scan() {
|
||||
p := all.Next()
|
||||
log.Info("read in patch:", p.Filename)
|
||||
}
|
||||
err = me.forge.SendPatchSet(pset)
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
}
|
||||
|
||||
func sendMasterDiff() {
|
||||
pset, err := me.forge.MakeMasterPatchSet()
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
all := pset.SortByFilename()
|
||||
for all.Scan() {
|
||||
p := all.Next()
|
||||
log.Info("read in patch:", p.Filename)
|
||||
}
|
||||
err = me.forge.SendPatchSet(pset)
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/user"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func httpPost(url string, data []byte) ([]byte, error) {
|
||||
var err error
|
||||
var req *http.Request
|
||||
|
||||
// data := []byte("some junk")
|
||||
// url := "https://go.wit.com/register/"
|
||||
|
||||
req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer(data))
|
||||
log.Info("httpPost() with len", len(data), "url", url)
|
||||
|
||||
usr, _ := user.Current()
|
||||
req.Header.Set("author", usr.Username)
|
||||
hostname, _ := os.Hostname()
|
||||
req.Header.Set("hostname", hostname)
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return []byte("client.Do(req) error"), err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
log.Info("httpPost() with len", len(data))
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return body, err
|
||||
}
|
||||
|
||||
// test := strings.TrimSpace(string(body))
|
||||
// log.Info("go.wit.com returned body:", test)
|
||||
// if test == "OK" {
|
||||
// return body, nil
|
||||
// }
|
||||
|
||||
return body, nil
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func sendPatches(pset *forgepb.Patchs) error {
|
||||
var url string
|
||||
url = me.urlbase + "/patchset"
|
||||
msg, err := pset.Marshal()
|
||||
if err != nil {
|
||||
log.Info("proto.Marshal() failed:", err)
|
||||
return err
|
||||
}
|
||||
log.Info("proto.Marshal() msg len", len(msg))
|
||||
body, err := httpPost(url, msg)
|
||||
if err != nil {
|
||||
log.Info("httpPost() failed:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
test := strings.TrimSpace(string(body))
|
||||
// log.Info("virtigo returned body:", test)
|
||||
for _, line := range strings.Split(test, "\n") {
|
||||
log.Info("got back:", line)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func sendDevelDiff() {
|
||||
pset, err := me.forge.MakeDevelPatchSet()
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
if err := sendPatches(pset); err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
|
||||
/*
|
||||
all := pset.SortByFilename()
|
||||
for all.Scan() {
|
||||
p := all.Next()
|
||||
log.Info("read in patch:", p.Filename)
|
||||
}
|
||||
err = me.forge.SendPatchSet(pset)
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func sendMasterDiff() {
|
||||
pset, err := me.forge.MakeMasterPatchSet()
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
all := pset.SortByFilename()
|
||||
for all.Scan() {
|
||||
p := all.Next()
|
||||
log.Info("read in patch:", p.Filename)
|
||||
}
|
||||
err = me.forge.SendPatchSet(pset)
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ type mainType struct {
|
|||
found *gitpb.Repos // stores the list of repos to process things on
|
||||
foundPaths []string // stores gopaths to act on (when doing go-clone)
|
||||
configSave bool // if the config file should be saved after finishing
|
||||
urlbase string // base URL
|
||||
|
||||
// our view of the repositories
|
||||
repos *repoWindow
|
||||
|
|
Loading…
Reference in New Issue