forge/find.go

168 lines
3.2 KiB
Go
Raw Normal View History

2025-02-01 11:57:52 -06:00
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
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
2025-02-21 18:31:26 -06:00
func (f *FindCmd) findRepos() *gitpb.Repos {
2024-12-27 03:39:53 -06:00
if f == nil {
findMine()
2025-02-21 18:31:26 -06:00
return me.found
2024-12-27 03:39:53 -06:00
}
2024-12-05 12:29:47 -06:00
2024-12-27 03:39:53 -06:00
if f.All {
findAll()
2025-02-21 18:31:26 -06:00
return me.found
2024-12-27 03:39:53 -06:00
}
2024-12-05 12:29:47 -06:00
2024-12-27 03:39:53 -06:00
if f.Private {
findPrivate()
2025-02-21 18:31:26 -06:00
return me.found
}
2024-12-27 03:39:53 -06:00
if f.Mine {
findMine()
2025-02-21 18:31:26 -06:00
return me.found
2024-12-27 03:39:53 -06:00
}
2024-12-27 03:39:53 -06:00
if f.Favorites {
findFavorites()
2025-02-21 18:31:26 -06:00
return me.found
}
2024-12-27 03:39:53 -06:00
if f.Dirty {
2025-02-21 18:31:26 -06:00
return findDirty()
}
2025-01-18 23:25:55 -06:00
if f.User {
findUser()
2025-02-21 18:31:26 -06:00
return me.found
2025-01-18 23:25:55 -06:00
}
findAll()
2025-02-21 18:31:26 -06:00
return me.found
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()
2025-02-10 23:42:21 -06:00
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
2025-02-21 18:31:26 -06:00
func findDirty() *gitpb.Repos {
found := gitpb.NewRepos()
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
var repo *gitpb.Repo
repo = all.Next()
if repo.IsDirty() {
2025-02-21 18:31:26 -06:00
found.AppendByGoPath(repo)
}
}
2025-02-21 18:31:26 -06:00
return found
}
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-02-07 19:10:37 -06:00
if repo.GetTargetVersion() != "" {
// add everything that has a target version set
me.found.AppendByGoPath(repo)
2025-01-28 17:35:18 -06:00
continue
}
2025-01-28 13:58:41 -06:00
if repo.IsDirty() {
2025-02-07 19:10:37 -06:00
// always add dirty branches
2025-01-28 13:58:41 -06:00
me.found.AppendByGoPath(repo)
continue
}
2025-02-07 19:10:37 -06:00
if repo.GetUserVersion() == "" || repo.GetUserVersion() == "uerr" {
// skip anything without a user branch
continue
}
2025-01-28 13:58:41 -06:00
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
}
2025-02-15 18:55:35 -06:00
// this is an old test to see if the current 'last tag' is accurate and should be removed
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
continue
}
if repo.GetLastTag() != repo.GetMasterVersion() {
me.found.AppendByGoPath(repo)
repo.FindLastTag()
continue
}
2025-01-28 13:58:41 -06:00
}
}