fixes along the way
This commit is contained in:
parent
d972937cca
commit
d3e1a7ec8f
|
@ -22,7 +22,7 @@ func FindGoSrc() (string, error) {
|
||||||
if pwd, err := digup(pwd); err == nil {
|
if pwd, err := digup(pwd); err == nil {
|
||||||
log.Info("using go.work file in directory", pwd)
|
log.Info("using go.work file in directory", pwd)
|
||||||
// found an existing go.work file
|
// found an existing go.work file
|
||||||
os.Chdir(pwd)
|
// os.Chdir(pwd)
|
||||||
return pwd, nil
|
return pwd, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func useGoSrc() (string, error) {
|
||||||
}
|
}
|
||||||
pwd := filepath.Join(homeDir, "go/src")
|
pwd := filepath.Join(homeDir, "go/src")
|
||||||
shell.Mkdir(pwd)
|
shell.Mkdir(pwd)
|
||||||
os.Chdir(pwd)
|
// os.Chdir(pwd)
|
||||||
return pwd, nil
|
return pwd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
77
goSrcScan.go
77
goSrcScan.go
|
@ -1,11 +1,13 @@
|
||||||
package forgepb
|
package forgepb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/destel/rill"
|
||||||
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,47 +17,30 @@ func (f *Forge) ScanGoSrc() (bool, error) {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var gopaths []string
|
||||||
for _, dir := range dirs {
|
for _, dir := range dirs {
|
||||||
if strings.HasPrefix(dir, f.goSrc) {
|
if strings.HasPrefix(dir, f.goSrc) {
|
||||||
gopath := strings.TrimPrefix(dir, f.goSrc)
|
gopath := strings.TrimPrefix(dir, f.goSrc)
|
||||||
gopath = strings.Trim(gopath, "/")
|
gopath = strings.Trim(gopath, "/")
|
||||||
// log.Info("ScanGoSrc() ok:", f.goSrc, gopath)
|
gopaths = append(gopaths, gopath)
|
||||||
newr, err := f.Repos.NewGoPath(f.goSrc, gopath)
|
|
||||||
if err != nil {
|
|
||||||
log.Log(FORGEPBWARN, "init failed", err)
|
|
||||||
panic("crapnuts")
|
|
||||||
}
|
|
||||||
log.Info("init worked for", newr.GoPath)
|
|
||||||
// try to guess what the 'master' branch is
|
|
||||||
if newr.IsBranch("guimaster") {
|
|
||||||
newr.SetMasterBranchName("guimaster")
|
|
||||||
} else if newr.IsBranch("master") {
|
|
||||||
newr.SetMasterBranchName("master")
|
|
||||||
} else if newr.IsBranch("main") {
|
|
||||||
newr.SetMasterBranchName("main")
|
|
||||||
} else {
|
|
||||||
newr.SetMasterBranchName("masterFIXME")
|
|
||||||
}
|
|
||||||
|
|
||||||
if newr.IsBranch("guidevel") {
|
|
||||||
newr.SetDevelBranchName("guidevel")
|
|
||||||
} else if newr.IsBranch("devel") {
|
|
||||||
newr.SetDevelBranchName("devel")
|
|
||||||
} else {
|
|
||||||
newr.SetDevelBranchName("develFIXME")
|
|
||||||
}
|
|
||||||
|
|
||||||
usr, _ := user.Current()
|
|
||||||
uname := usr.Username
|
|
||||||
if newr.IsBranch(uname) {
|
|
||||||
newr.SetUserBranchName(uname)
|
|
||||||
} else {
|
|
||||||
newr.SetUserBranchName(uname + "FIXME")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
log.Log(FORGEPBWARN, "ScanGoSrc() bad:", dir)
|
log.Log(FORGEPBWARN, "ScanGoSrc() bad:", dir)
|
||||||
|
return false, errors.New("forgepb.ScanGoSrc() bad dir: " + dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
f.rillScanDirs(gopaths)
|
||||||
|
|
||||||
|
/*
|
||||||
|
for _, dir := range dirs {
|
||||||
|
if strings.HasPrefix(dir, f.goSrc) {
|
||||||
|
gopath := strings.TrimPrefix(dir, f.goSrc)
|
||||||
|
gopath = strings.Trim(gopath, "/")
|
||||||
|
repo, err := f.Repos.NewGoPath(f.goSrc, gopath)
|
||||||
|
} else {
|
||||||
|
log.Log(FORGEPBWARN, "ScanGoSrc() bad:", dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,3 +101,27 @@ func rillAddDirs(gopaths []string) {
|
||||||
fmt.Println("Error:", err)
|
fmt.Println("Error:", err)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// rill is awesome. long live rill
|
||||||
|
// attempt scan with rill
|
||||||
|
func (f *Forge) rillScanDirs(gopaths []string) error {
|
||||||
|
// Convert a slice of user IDs into a channel
|
||||||
|
ids := rill.FromSlice(gopaths, nil)
|
||||||
|
|
||||||
|
// Read users from the API.
|
||||||
|
// Concurrency = 20
|
||||||
|
dirs := rill.Map(ids, 20, func(id string) (*gitpb.Repo, error) {
|
||||||
|
return f.Repos.NewGoPath(f.goSrc, id)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Activate users.
|
||||||
|
// Concurrency = 10
|
||||||
|
err := rill.ForEach(dirs, 10, func(repo *gitpb.Repo) error {
|
||||||
|
// could do something here
|
||||||
|
// fmt.Printf("Repo found : %s\n", repo.GoPath)
|
||||||
|
// repo.Run([]string{"git", "pull"})
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
2
init.go
2
init.go
|
@ -47,6 +47,6 @@ func Init() *Forge {
|
||||||
|
|
||||||
f.goSrc = os.Getenv("FORGE_GOSRC")
|
f.goSrc = os.Getenv("FORGE_GOSRC")
|
||||||
f.ScanGoSrc()
|
f.ScanGoSrc()
|
||||||
log.Warn("GOT HERE. forge.Init(). f can not be nil")
|
log.Info("forge.Init() found", f.Repos.Len(), "repos in", f.goSrc)
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
42
repoNew.go
42
repoNew.go
|
@ -1,7 +1,45 @@
|
||||||
package forgepb
|
package forgepb
|
||||||
|
|
||||||
import "go.wit.com/lib/protobuf/gitpb"
|
import (
|
||||||
|
"os/user"
|
||||||
|
|
||||||
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
func (f *Forge) NewGoPath(gopath string) (*gitpb.Repo, error) {
|
func (f *Forge) NewGoPath(gopath string) (*gitpb.Repo, error) {
|
||||||
return f.Repos.NewGoPath(f.goSrc, gopath)
|
newr, err := f.Repos.NewGoPath(f.goSrc, gopath)
|
||||||
|
if err != nil {
|
||||||
|
log.Log(FORGEPBWARN, "init failed", err)
|
||||||
|
panic("crapnuts")
|
||||||
|
}
|
||||||
|
log.Info("init worked for", newr.GoPath)
|
||||||
|
// try to guess what the 'master' branch is
|
||||||
|
if newr.IsBranch("guimaster") {
|
||||||
|
newr.SetMasterBranchName("guimaster")
|
||||||
|
} else if newr.IsBranch("master") {
|
||||||
|
newr.SetMasterBranchName("master")
|
||||||
|
} else if newr.IsBranch("main") {
|
||||||
|
newr.SetMasterBranchName("main")
|
||||||
|
} else {
|
||||||
|
newr.SetMasterBranchName("masterFIXME")
|
||||||
|
}
|
||||||
|
|
||||||
|
if newr.IsBranch("guidevel") {
|
||||||
|
newr.SetDevelBranchName("guidevel")
|
||||||
|
} else if newr.IsBranch("devel") {
|
||||||
|
newr.SetDevelBranchName("devel")
|
||||||
|
} else {
|
||||||
|
newr.SetDevelBranchName("develFIXME")
|
||||||
|
}
|
||||||
|
|
||||||
|
usr, _ := user.Current()
|
||||||
|
uname := usr.Username
|
||||||
|
if newr.IsBranch(uname) {
|
||||||
|
newr.SetUserBranchName(uname)
|
||||||
|
} else {
|
||||||
|
newr.SetUserBranchName(uname + "FIXME")
|
||||||
|
}
|
||||||
|
|
||||||
|
return newr, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue