summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--goSrcFind.go4
-rw-r--r--goSrcScan.go77
-rw-r--r--init.go2
-rw-r--r--repoNew.go42
4 files changed, 86 insertions, 39 deletions
diff --git a/goSrcFind.go b/goSrcFind.go
index b4ee277..a035205 100644
--- a/goSrcFind.go
+++ b/goSrcFind.go
@@ -22,7 +22,7 @@ func FindGoSrc() (string, error) {
if pwd, err := digup(pwd); err == nil {
log.Info("using go.work file in directory", pwd)
// found an existing go.work file
- os.Chdir(pwd)
+ // os.Chdir(pwd)
return pwd, nil
}
}
@@ -42,7 +42,7 @@ func useGoSrc() (string, error) {
}
pwd := filepath.Join(homeDir, "go/src")
shell.Mkdir(pwd)
- os.Chdir(pwd)
+ // os.Chdir(pwd)
return pwd, nil
}
diff --git a/goSrcScan.go b/goSrcScan.go
index 0f85c33..4e23fed 100644
--- a/goSrcScan.go
+++ b/goSrcScan.go
@@ -1,11 +1,13 @@
package forgepb
import (
+ "errors"
"os"
- "os/user"
"path/filepath"
"strings"
+ "github.com/destel/rill"
+ "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
@@ -15,47 +17,30 @@ func (f *Forge) ScanGoSrc() (bool, error) {
return false, err
}
+ var gopaths []string
for _, dir := range dirs {
if strings.HasPrefix(dir, f.goSrc) {
gopath := strings.TrimPrefix(dir, f.goSrc)
gopath = strings.Trim(gopath, "/")
- // log.Info("ScanGoSrc() ok:", 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")
- }
+ gopaths = append(gopaths, gopath)
} else {
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
}
@@ -116,3 +101,27 @@ func rillAddDirs(gopaths []string) {
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
+}
diff --git a/init.go b/init.go
index a991582..120d57a 100644
--- a/init.go
+++ b/init.go
@@ -47,6 +47,6 @@ func Init() *Forge {
f.goSrc = os.Getenv("FORGE_GOSRC")
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
}
diff --git a/repoNew.go b/repoNew.go
index 3ee2b38..71d7776 100644
--- a/repoNew.go
+++ b/repoNew.go
@@ -1,7 +1,45 @@
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) {
- 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
}