summaryrefslogtreecommitdiff
path: root/rill.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-03 00:35:50 -0600
committerJeff Carr <[email protected]>2024-12-03 00:35:50 -0600
commit1d1d8e7eea642cd3fc546101b4899ec1db81e3b7 (patch)
tree0a313aa1a49b1aeaacfc3df802171193ed76a324 /rill.go
parent7a90613c91fa5c06b6fbe5a7a6e48fbba722877d (diff)
lots of code hopefully better than before
Diffstat (limited to 'rill.go')
-rw-r--r--rill.go96
1 files changed, 96 insertions, 0 deletions
diff --git a/rill.go b/rill.go
new file mode 100644
index 0000000..f1b6b37
--- /dev/null
+++ b/rill.go
@@ -0,0 +1,96 @@
+package gitpb
+
+// runs git, parses output
+// types faster than you can
+
+import (
+ "errors"
+ "sort"
+ "strings"
+ "time"
+
+ "go.wit.com/log"
+)
+
+func (all *GitTags) SortByAge() *GitTagIterator {
+ packs := all.selectAllGitTag()
+
+ sort.Sort(GitTagAge(packs))
+
+ iterator := NewGitTagIterator(packs)
+ return iterator
+}
+
+type GitTagAge []*GitTag
+
+func (a GitTagAge) Len() int { return len(a) }
+
+// sorts in ? order
+func (a GitTagAge) Less(i, j int) bool {
+ if time.Since(a[i].Authordate.AsTime()) < time.Since(a[j].Authordate.AsTime()) {
+ return true
+ }
+ return false
+}
+func (a GitTagAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
+
+// rill is awesome. long live rill
+// attempt scan with rill
+func (all *Repos) rillGitPull() error {
+ loop := all.SortByGoPath()
+ for loop.Scan() {
+ t := loop.Next()
+ log.Info("repo", t.GoPath)
+ }
+ /*
+ packs := all.selectAllRepo()
+ // Convert a slice of user IDs into a channel
+ ids := rill.FromSlice(packs, nil)
+
+ // Read users from the API.
+ // Concurrency = 20
+ dirs := rill.Map(ids, 20, func(id string) (*Repo, error) {
+ return packs[id], nil
+ })
+
+ // Activate users.
+ // Concurrency = 10
+ err := rill.ForEach(dirs, 10, func(repo *Repo) error {
+ // could do something here
+ // fmt.Printf("Repo found : %s\n", repo.GoPath)
+ // repo.Run([]string{"git", "pull"})
+ return nil
+ })
+ */
+ return nil
+}
+
+var ErrorMissingGitConfig error = errors.New("missing .git/config")
+var ErrorGitPullOnLocal error = errors.New("git pull on local only branch")
+
+// checks to see if you can do a 'git pull'
+func (repo *Repo) IsOnlyLocalTag(currentName string) bool {
+ log.Warn("IsOnlyLocalTag(currentName string) not re-implemented yet")
+ return false
+}
+
+func (repo *Repo) GitPull() (string, error) {
+ currentName := repo.GetCurrentBranchName()
+ if repo.IsOnlyLocalTag(currentName) {
+ return "", ErrorGitPullOnLocal
+ }
+ var cmd []string
+ cmd = append(cmd, "git", "pull")
+ r := repo.Run(cmd)
+ output := strings.Join(r.Stdout, "\n")
+ if r.Error != nil {
+ output = "git error_,,,_a_,,,_b_,,,c"
+ }
+ if r.Error == nil {
+ log.Log(GITPBWARN, "git pull ran", repo.GetGoPath())
+ log.Log(GITPBWARN, "git pull output", output)
+ } else {
+ log.Log(GITPBWARN, "git pull error", repo.GetGoPath(), r.Error)
+ }
+ return output, r.Error
+}