From 7615317ca72347429f665dc7db9a0fe49d86cc55 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 29 Nov 2024 16:23:13 -0600 Subject: always use singular Signed-off-by: Jeff Carr --- repo.helpers.go | 46 ++++++++++++++++++++++++++++++++++ repo.new.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ repos.helpers.go | 46 ---------------------------------- repos.new.go | 75 -------------------------------------------------------- 4 files changed, 121 insertions(+), 121 deletions(-) create mode 100644 repo.helpers.go create mode 100644 repo.new.go delete mode 100644 repos.helpers.go delete mode 100644 repos.new.go diff --git a/repo.helpers.go b/repo.helpers.go new file mode 100644 index 0000000..50f3277 --- /dev/null +++ b/repo.helpers.go @@ -0,0 +1,46 @@ +package gitpb + +// delete a gopath: +// myrepos.DeleteByPath("go.wit.com/apps/go-clone") +func (all *Repos) DeleteByPath(gopath string) *Repo { + reposMu.Lock() + defer reposMu.Unlock() + + for i, _ := range all.Repos { + if all.Repos[i].GoPath == gopath { + all.Repos[i] = all.Repos[len(all.Repos)-1] + all.Repos = all.Repos[:len(all.Repos)-1] + return nil + } + } + return nil +} + +// find a package by gopath +func (all *Repos) FindByGoPath(gopath string) *Repo { + reposMu.RLock() + defer reposMu.RUnlock() + + for _, p := range all.Repos { + if p.GoPath == gopath { + return p + } + } + + return nil +} + +// enforces no duplicate gopath's +func (all *Repos) add(newP *Repo) bool { + reposMu.Lock() + defer reposMu.Unlock() + + for _, p := range all.Repos { + if p.GoPath == newP.GoPath { + return false + } + } + + all.Repos = append(all.Repos, newP) + return true +} diff --git a/repo.new.go b/repo.new.go new file mode 100644 index 0000000..1480051 --- /dev/null +++ b/repo.new.go @@ -0,0 +1,75 @@ +package gitpb + +import ( + "bufio" + "errors" + "os" + "path/filepath" + "strings" + + "go.wit.com/log" +) + +// scans in a new git repo. If it detects the repo is a golang project, +// then it parses the go.mod/go.sum files +// TODO: try adding python, rails, perl, rust, other language things? +// I probably will never have time to try that, but I'd take patches for anyone +// that might see this note and feel so inclined. +func (all *Repos) NewGoPath(basepath string, gopath string) (*Repo, error) { + if r := all.FindByGoPath(gopath); r != nil { + // already had this gopath + return r, nil + } + + // if .git doesn't exist, error out here + gitpath := filepath.Join(basepath, gopath, ".git") + _, err := os.Stat(gitpath) + if err != nil { + return nil, err + } + + // add a new one here + newr := Repo{ + FullPath: filepath.Join(basepath, gopath), + GoPath: gopath, + } + // newr.UpdateGit() + newr.UpdateGitTags() + + all.add(&newr) + return &newr, nil +} + +// Detect a 'Primative' package. Sets the isPrimative flag +// will return true if the repo is truly not dependent on _anything_ else +// like spew or lib/widget +// it assumes go mod ran init and tidy ran without error +func (repo *Repo) isPrimativeGoMod() (bool, error) { + // go mod init & go mod tidy ran without errors + log.Log(GITPB, "isPrimativeGoMod()", repo.FullPath) + tmp := filepath.Join(repo.FullPath, "go.mod") + gomod, err := os.Open(tmp) + if err != nil { + log.Log(GITPB, "missing go.mod", repo.FullPath) + repo.GoDeps = nil + return false, err + } + defer gomod.Close() + + scanner := bufio.NewScanner(gomod) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + + parts := strings.Split(line, " ") + log.Log(GITPB, " gomod:", parts) + if len(parts) >= 1 { + log.Log(GITPB, " gomod: part[0] =", parts[0]) + if parts[0] == "require" { + log.Log(GITPB, " should return false here") + return false, errors.New("go.mod file is not primative") + } + + } + } + return true, nil +} diff --git a/repos.helpers.go b/repos.helpers.go deleted file mode 100644 index 50f3277..0000000 --- a/repos.helpers.go +++ /dev/null @@ -1,46 +0,0 @@ -package gitpb - -// delete a gopath: -// myrepos.DeleteByPath("go.wit.com/apps/go-clone") -func (all *Repos) DeleteByPath(gopath string) *Repo { - reposMu.Lock() - defer reposMu.Unlock() - - for i, _ := range all.Repos { - if all.Repos[i].GoPath == gopath { - all.Repos[i] = all.Repos[len(all.Repos)-1] - all.Repos = all.Repos[:len(all.Repos)-1] - return nil - } - } - return nil -} - -// find a package by gopath -func (all *Repos) FindByGoPath(gopath string) *Repo { - reposMu.RLock() - defer reposMu.RUnlock() - - for _, p := range all.Repos { - if p.GoPath == gopath { - return p - } - } - - return nil -} - -// enforces no duplicate gopath's -func (all *Repos) add(newP *Repo) bool { - reposMu.Lock() - defer reposMu.Unlock() - - for _, p := range all.Repos { - if p.GoPath == newP.GoPath { - return false - } - } - - all.Repos = append(all.Repos, newP) - return true -} diff --git a/repos.new.go b/repos.new.go deleted file mode 100644 index 1480051..0000000 --- a/repos.new.go +++ /dev/null @@ -1,75 +0,0 @@ -package gitpb - -import ( - "bufio" - "errors" - "os" - "path/filepath" - "strings" - - "go.wit.com/log" -) - -// scans in a new git repo. If it detects the repo is a golang project, -// then it parses the go.mod/go.sum files -// TODO: try adding python, rails, perl, rust, other language things? -// I probably will never have time to try that, but I'd take patches for anyone -// that might see this note and feel so inclined. -func (all *Repos) NewGoPath(basepath string, gopath string) (*Repo, error) { - if r := all.FindByGoPath(gopath); r != nil { - // already had this gopath - return r, nil - } - - // if .git doesn't exist, error out here - gitpath := filepath.Join(basepath, gopath, ".git") - _, err := os.Stat(gitpath) - if err != nil { - return nil, err - } - - // add a new one here - newr := Repo{ - FullPath: filepath.Join(basepath, gopath), - GoPath: gopath, - } - // newr.UpdateGit() - newr.UpdateGitTags() - - all.add(&newr) - return &newr, nil -} - -// Detect a 'Primative' package. Sets the isPrimative flag -// will return true if the repo is truly not dependent on _anything_ else -// like spew or lib/widget -// it assumes go mod ran init and tidy ran without error -func (repo *Repo) isPrimativeGoMod() (bool, error) { - // go mod init & go mod tidy ran without errors - log.Log(GITPB, "isPrimativeGoMod()", repo.FullPath) - tmp := filepath.Join(repo.FullPath, "go.mod") - gomod, err := os.Open(tmp) - if err != nil { - log.Log(GITPB, "missing go.mod", repo.FullPath) - repo.GoDeps = nil - return false, err - } - defer gomod.Close() - - scanner := bufio.NewScanner(gomod) - for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - - parts := strings.Split(line, " ") - log.Log(GITPB, " gomod:", parts) - if len(parts) >= 1 { - log.Log(GITPB, " gomod: part[0] =", parts[0]) - if parts[0] == "require" { - log.Log(GITPB, " should return false here") - return false, errors.New("go.mod file is not primative") - } - - } - } - return true, nil -} -- cgit v1.2.3