summaryrefslogtreecommitdiff
path: root/find.go
diff options
context:
space:
mode:
Diffstat (limited to 'find.go')
-rw-r--r--find.go197
1 files changed, 197 insertions, 0 deletions
diff --git a/find.go b/find.go
new file mode 100644
index 0000000..f6fbbba
--- /dev/null
+++ b/find.go
@@ -0,0 +1,197 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "go.wit.com/lib/protobuf/gitpb"
+)
+
+// this populates a slice of protobuf records representing each git repo
+// var found []*gitpb.Repo
+//
+// so, it makes a subset of repos that are then used performing actions on
+//
+// by default, it adds every repo
+
+func doFind() *gitpb.Repos {
+ if argv.Show == nil {
+ return findAll()
+ }
+
+ if argv.Show.Repo.Mine {
+ return findMine()
+ }
+
+ if argv.Show.Dirty != nil {
+ return me.forge.FindDirty()
+ }
+
+ return findAll()
+}
+
+func findRepos() *gitpb.Repos {
+ if argv.Show == nil {
+ return findMine()
+ }
+
+ if argv.Show.Dirty != nil {
+ return me.forge.FindDirty()
+ }
+
+ if argv.Show.Repo == nil {
+ return findAll()
+ }
+
+ if argv.Show.Repo.All {
+ return findAll()
+ }
+
+ if argv.Show.Repo.Private {
+ return findPrivate()
+ }
+
+ if argv.Show.Repo.Mine {
+ return findMine()
+ }
+
+ if argv.Show.Repo.Favorites {
+ return findFavorites()
+ }
+
+ if argv.Show.Repo.User {
+ return findUser()
+ }
+
+ return findAll()
+}
+
+func findPrivate() *gitpb.Repos {
+ found := gitpb.NewRepos()
+ for repo := range me.forge.Repos.IterByFullPath() {
+ if me.forge.Config.IsPrivate(repo.Namespace) {
+ found.AppendByFullPath(repo)
+ }
+ }
+
+ return found
+}
+
+// finds repos that are writable
+func findMine() *gitpb.Repos {
+ found := gitpb.NewRepos()
+
+ // log.Printf("get mine %s\n", me.forge.GetGoSrc())
+ for repo := range me.forge.Repos.IterByFullPath() {
+
+ if me.forge.Config.IsWritable(repo.Namespace) {
+ found.AppendByFullPath(repo)
+ }
+ }
+ return found
+}
+
+// finds repos the user has marked as favorites in the forge .config
+func findFavorites() *gitpb.Repos {
+ found := gitpb.NewRepos()
+
+ // log.Printf("get favorites %s\n", me.forge.GetGoSrc())
+ for repo := range me.forge.Repos.IterByFullPath() {
+
+ if me.forge.Config.IsFavorite(repo.Namespace) {
+ found.AppendByFullPath(repo)
+ }
+ }
+ return found
+}
+
+func findAll() *gitpb.Repos {
+ found := gitpb.NewRepos()
+ for repo := range me.forge.Repos.IterByFullPath() {
+ found.AppendByFullPath(repo)
+ }
+ return found
+}
+
+func find50() *gitpb.Repos {
+ count := 0
+ found := gitpb.NewRepos()
+ for repo := range me.forge.Repos.IterByFullPath() {
+ found.AppendByFullPath(repo)
+ if count > 50 {
+ return found
+ }
+ count += 1
+ }
+ return found
+}
+
+func findUser() *gitpb.Repos {
+ found := gitpb.NewRepos()
+
+ for repo := range me.forge.Repos.IterByFullPath() {
+ if repo.GetCurrentBranchName() == repo.GetUserBranchName() {
+ found.AppendByFullPath(repo)
+ }
+ }
+ return found
+}
+
+func findPublishable() *gitpb.Repos {
+ found := gitpb.NewRepos()
+
+ for repo := range me.forge.Repos.IterByFullPath() {
+ if repo.GetTargetVersion() == "" {
+ continue
+ }
+ found.AppendByFullPath(repo)
+ }
+ return found
+}
+
+func findReposWithPatches() *gitpb.Repos {
+ found := gitpb.NewRepos()
+
+ for repo := range me.forge.Repos.IterByFullPath() {
+ if repo.IsDirty() {
+ // always add dirty branches
+ found.AppendByFullPath(repo)
+ continue
+ }
+ if repo.GetUserVersion() == "" || repo.GetUserVersion() == "uerr" {
+ // skip anything without a user branch
+ continue
+ }
+ if repo.GetUserVersion() != repo.GetDevelVersion() {
+ found.AppendByFullPath(repo)
+ continue
+ }
+
+ // ignore read-only repos for checks below here
+ if me.forge.Config.IsReadOnly(repo.Namespace) {
+ continue
+ }
+
+ // show anything that differs between 'devel' & 'master' branches
+ if repo.GetDevelVersion() != repo.GetMasterVersion() {
+ // this repo.State code isn't great, but it got me here quickly
+ // I'll defend my code by saying it's faster for me if I do dumb things
+ // sometimes and fix them later. Probably some employee will have to
+ // fix this. if that is the case I owe you lunch. or stock options
+ if repo.State == "DEVEL behind MASTER" {
+ // log.Info("repo state", repo.FullPath, repo.State)
+ continue
+ }
+ found.AppendByFullPath(repo)
+ continue
+ }
+
+ // this is an old test to see if the current 'last tag' is accurate and should be removed
+ if repo.GetLastTag() != repo.GetMasterVersion() {
+ found.AppendByFullPath(repo)
+ repo.FindLastTag()
+ continue
+ }
+ }
+ return found
+}