summaryrefslogtreecommitdiff
path: root/doVerifyNamespace.go
diff options
context:
space:
mode:
Diffstat (limited to 'doVerifyNamespace.go')
-rw-r--r--doVerifyNamespace.go59
1 files changed, 20 insertions, 39 deletions
diff --git a/doVerifyNamespace.go b/doVerifyNamespace.go
index b3a6820..cc42108 100644
--- a/doVerifyNamespace.go
+++ b/doVerifyNamespace.go
@@ -5,6 +5,7 @@ package main
import (
"errors"
+ "fmt"
"path/filepath"
"go.wit.com/lib/env"
@@ -12,54 +13,34 @@ import (
"go.wit.com/log"
)
-func cleanNamespace(r *gitpb.Repo) string {
+func doCleanNamespace(r *gitpb.Repo) error {
// check for GO repos
gowork := env.Get("gopath")
// todo: detect if using go.work file
newpath, err := filepath.Rel(gowork, r.FullPath)
- // log.Info("cleanNamespace()", newpath, gowork, "is gowork. fullpath:", r.FullPath)
- if err == nil {
- // log.Info("cleanNamespace returned", newpath)
- // relative path to gosrc or gowork is the namespace
- return newpath
+ if err != nil {
+ log.Info("cleanNamespace got err", newpath, err)
+ // check for other stuff. use the URLs
+ return err
}
- log.Info("cleanNamespace got err", newpath, err)
- // check for other stuff. use the URLs
- return ""
+ if newpath == r.Namespace {
+ // namespace was already set right
+ return nil
+ }
+ r.Namespace = newpath
+ err = errors.New("namepace changed")
+ s := fmt.Sprintf("old(%s), new(%s)", r.Namespace, newpath)
+ return errors.Join(errors.New(s), err)
}
// checks to see if the r.Namespace seems right
func doVerifyNamespace() (string, error) {
- var s string = "doVerifyNamespace()"
- var err error
- var counter int
- for r := range me.forge.Repos.IterAll() {
- newpath := cleanNamespace(r)
- if newpath == "" {
- // log.Info("didn't work", r.Namespace, "to", newpath)
- // didn't work
- } else if newpath == r.Namespace {
- // already good namespace.
- continue
- } else if newpath != r.Namespace {
- counter += 1
- log.Info("Changed", r.FullPath, "to", newpath)
- r.Namespace = newpath
- continue
- }
- counter += 1
- log.Info("cleanNamespace() didn't match", r.Namespace)
- }
- if counter != 0 {
- err = errors.New(log.Sprintf("%d namespaces were invalid", counter))
- }
-
- if env.True("DryRun") {
- return s, err
- }
- if counter != 0 {
+ fixed := me.forge.RunOnRepos(me.forge.Repos, doCleanNamespace)
+ if fixed.Len() != 0 {
+ fixed = fixed.SortActual()
+ footer := me.forge.PrintDefaultTB(fixed)
me.forge.Repos.SaveVerbose()
+ return "changed namespaces: " + footer, nil
}
-
- return s, err
+ return "no namespaces changed", nil
}