submit-patchset/find.go

150 lines
2.5 KiB
Go
Raw Permalink Normal View History

2024-12-05 12:29:47 -06:00
package main
import (
"go.wit.com/lib/protobuf/gitpb"
)
// this populates a slice of protobuf records representing each git repo
// var me.found []*gitpb.Repo
//
// so, it makes a subset of repos that are then used performing actions on
//
// by default, it adds every repo
2024-12-27 03:39:53 -06:00
func (f *FindCmd) findRepos() {
if f == nil {
findMine()
return
}
2024-12-05 12:29:47 -06:00
2025-01-29 19:59:55 -06:00
if f.Pub != nil {
findPublishable()
return
}
2024-12-27 03:39:53 -06:00
if f.All {
findAll()
2024-12-27 03:39:53 -06:00
return
}
2024-12-05 12:29:47 -06:00
2024-12-27 03:39:53 -06:00
if f.Private {
findPrivate()
return
}
2024-12-27 03:39:53 -06:00
if f.Mine {
findMine()
2024-12-27 03:39:53 -06:00
return
}
2024-12-27 03:39:53 -06:00
if f.Favorites {
findFavorites()
return
}
2024-12-27 03:39:53 -06:00
if f.Dirty {
findDirty()
return
}
2025-01-18 23:25:55 -06:00
if f.User {
findUser()
return
}
findAll()
2024-12-27 03:39:53 -06:00
}
func findPrivate() {
2024-12-17 06:36:00 -06:00
all := me.forge.Repos.SortByFullPath()
2024-12-11 19:32:04 -06:00
for all.Scan() {
repo := all.Next()
2024-12-17 06:36:00 -06:00
if me.forge.Config.IsPrivate(repo.GetGoPath()) {
me.found.AppendByGoPath(repo)
}
}
}
// finds repos that are writable
func findMine() {
// log.Printf("get mine %s\n", me.forge.GetGoSrc())
2024-12-17 06:36:00 -06:00
all := me.forge.Repos.SortByFullPath()
2024-12-11 19:32:04 -06:00
for all.Scan() {
repo := all.Next()
2024-12-17 06:36:00 -06:00
if me.forge.Config.IsWritable(repo.GetGoPath()) {
me.found.AppendByGoPath(repo)
}
}
}
// finds repos the user has marked as favorites in the forge .config
func findFavorites() {
// log.Printf("get favorites %s\n", me.forge.GetGoSrc())
2024-12-17 06:36:00 -06:00
all := me.forge.Repos.SortByFullPath()
2024-12-11 19:32:04 -06:00
for all.Scan() {
repo := all.Next()
2024-12-17 06:36:00 -06:00
if me.forge.Config.IsFavorite(repo.GetGoPath()) {
me.found.AppendByGoPath(repo)
}
}
}
// finds repos that git is reporting as dirty
func findDirty() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
var repo *gitpb.Repo
repo = all.Next()
if repo.IsDirty() {
me.found.AppendByGoPath(repo)
}
}
}
func findAll() {
2024-12-17 06:36:00 -06:00
all := me.forge.Repos.SortByFullPath()
2024-12-11 19:32:04 -06:00
for all.Scan() {
repo := all.Next()
me.found.AppendByGoPath(repo)
2024-12-05 12:29:47 -06:00
}
}
2025-01-18 23:25:55 -06:00
func findUser() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
if repo.GetCurrentBranchName() == repo.GetUserBranchName() {
me.found.AppendByGoPath(repo)
}
}
}
2025-01-28 13:58:41 -06:00
2025-01-29 19:59:55 -06:00
func findPublishable() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
if repo.GetTargetVersion() == "" {
continue
}
me.found.AppendByGoPath(repo)
}
}
2025-01-28 13:58:41 -06:00
func findReposWithPatches() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
2025-01-28 17:35:18 -06:00
if repo.GetUserVersion() == "" || repo.GetUserVersion() == "uerr" {
continue
}
2025-01-28 13:58:41 -06:00
if repo.IsDirty() {
me.found.AppendByGoPath(repo)
continue
}
if repo.GetUserVersion() != repo.GetDevelVersion() {
me.found.AppendByGoPath(repo)
2025-01-28 17:35:18 -06:00
continue
2025-01-28 13:58:41 -06:00
}
}
}