2024-02-17 08:39:55 -06:00
|
|
|
package repolist
|
|
|
|
|
|
|
|
import (
|
2024-03-09 09:23:41 -06:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2024-03-09 16:49:57 -06:00
|
|
|
"sort"
|
2024-03-09 09:23:41 -06:00
|
|
|
|
2024-11-08 06:43:45 -06:00
|
|
|
"github.com/go-cmd/cmd"
|
2024-02-19 19:43:21 -06:00
|
|
|
"go.wit.com/gui"
|
2024-02-19 21:11:32 -06:00
|
|
|
"go.wit.com/lib/gui/repostatus"
|
2024-02-18 17:56:25 -06:00
|
|
|
"go.wit.com/log"
|
2024-02-17 08:39:55 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func (r *RepoList) Hidden() bool {
|
2024-02-17 14:22:24 -06:00
|
|
|
return r.reposbox.Hidden()
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RepoList) Show() {
|
2024-02-17 14:22:24 -06:00
|
|
|
r.reposbox.Show()
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RepoList) Hide() {
|
2024-02-17 14:22:24 -06:00
|
|
|
r.reposbox.Hide()
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
2024-11-04 02:14:54 -06:00
|
|
|
// better name: use this
|
|
|
|
func (r *RepoList) FindRepoByName(path string) *RepoRow {
|
|
|
|
return r.FindRepo(path)
|
|
|
|
}
|
|
|
|
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoList) FindRepo(path string) *RepoRow {
|
2024-02-18 15:09:35 -06:00
|
|
|
repo, _ := me.allrepos[path]
|
|
|
|
return repo
|
|
|
|
}
|
|
|
|
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoList) AllRepos() []*RepoRow {
|
|
|
|
var all []*RepoRow
|
2024-02-17 08:39:55 -06:00
|
|
|
for _, repo := range me.allrepos {
|
|
|
|
all = append(all, repo)
|
|
|
|
}
|
|
|
|
return all
|
|
|
|
}
|
|
|
|
|
|
|
|
// deprecate this
|
2024-02-23 09:02:51 -06:00
|
|
|
func AllRepos() []*RepoRow {
|
|
|
|
var all []*RepoRow
|
2024-02-17 08:39:55 -06:00
|
|
|
for _, repo := range me.allrepos {
|
|
|
|
all = append(all, repo)
|
|
|
|
}
|
|
|
|
return all
|
|
|
|
}
|
|
|
|
|
2024-02-17 15:48:56 -06:00
|
|
|
// a human readable state of the current repo
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoRow) State() string {
|
2024-02-19 16:28:24 -06:00
|
|
|
return r.gitState.String()
|
2024-02-17 14:22:24 -06:00
|
|
|
}
|
|
|
|
|
2024-02-23 14:25:00 -06:00
|
|
|
func (r *RepoRow) Scan() int {
|
2024-02-17 14:22:24 -06:00
|
|
|
return r.NewScan()
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
2024-02-17 15:48:56 -06:00
|
|
|
// returns a name for human consuption only
|
|
|
|
// todo: implement nicknames
|
2024-02-23 09:02:51 -06:00
|
|
|
func (rs *RepoRow) Name() string {
|
2024-02-17 15:48:56 -06:00
|
|
|
if rs.Status.IsGoLang() {
|
|
|
|
return rs.Status.GoPath()
|
|
|
|
}
|
|
|
|
return rs.Status.Path()
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoRow) GoPath() string {
|
2024-02-17 15:48:56 -06:00
|
|
|
return r.Status.GoPath()
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoRow) CheckDirty() bool {
|
2024-02-17 15:48:56 -06:00
|
|
|
return r.Status.CheckDirty()
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoRow) IsDirty() bool {
|
2024-02-17 15:48:56 -06:00
|
|
|
return r.Status.IsDirty()
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoRow) ReadOnly() bool {
|
2024-02-19 19:43:21 -06:00
|
|
|
if r == nil {
|
|
|
|
log.Warn("ReadOnly() repo == nil")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if r.Status == nil {
|
|
|
|
log.Warn("ReadOnly() repo.Status == nil")
|
|
|
|
return false
|
|
|
|
}
|
2024-02-17 15:48:56 -06:00
|
|
|
return r.Status.ReadOnly()
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoRow) LastTag() string {
|
2024-02-19 19:43:21 -06:00
|
|
|
if r == nil {
|
|
|
|
log.Warn("LastTag() repo == nil")
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return r.lastTag.String()
|
2024-02-18 15:09:35 -06:00
|
|
|
}
|
|
|
|
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoRow) IsPerfect() bool {
|
2024-02-19 16:28:24 -06:00
|
|
|
if r.gitState.String() == "PERFECT" {
|
2024-02-17 08:39:55 -06:00
|
|
|
return true
|
|
|
|
}
|
2024-02-19 16:28:24 -06:00
|
|
|
if r.gitState.String() == "unchanged" {
|
2024-02-17 14:22:24 -06:00
|
|
|
return true
|
|
|
|
}
|
2024-02-17 08:39:55 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-11-08 06:43:45 -06:00
|
|
|
func (r *RepoRow) Run(cmd []string) cmd.Status {
|
|
|
|
return r.Status.Run(cmd)
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoRow) AllTags() []*repostatus.Tag {
|
2024-02-17 15:48:56 -06:00
|
|
|
return r.Status.Tags.ListAll()
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoRow) TagsBox() *repostatus.GitTagBox {
|
2024-02-17 15:48:56 -06:00
|
|
|
return r.Status.Tags
|
2024-02-17 08:39:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// todo, fix bool return for deletetag()
|
2024-02-23 09:02:51 -06:00
|
|
|
func (r *RepoRow) DeleteTag(t *repostatus.Tag) bool {
|
2024-02-17 15:48:56 -06:00
|
|
|
r.Status.DeleteTag(t)
|
2024-02-17 08:39:55 -06:00
|
|
|
return true
|
|
|
|
}
|
2024-02-19 19:43:21 -06:00
|
|
|
|
|
|
|
func (rl *RepoList) MirrorShownCount() *gui.Node {
|
|
|
|
return gui.RawMirror(rl.shownCount)
|
|
|
|
}
|
2024-02-20 14:45:09 -06:00
|
|
|
|
|
|
|
func (rl *RepoList) MirrorScanDuration() *gui.Node {
|
|
|
|
return gui.RawMirror(rl.duration)
|
|
|
|
}
|
2024-02-21 11:17:54 -06:00
|
|
|
|
|
|
|
func (rl *RepoList) Total() int {
|
|
|
|
return len(me.allrepos)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rl *RepoList) TotalGo() int {
|
|
|
|
var count int
|
|
|
|
for _, repo := range me.allrepos {
|
|
|
|
if repo.Status.IsGoLang() {
|
|
|
|
count += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|
2024-03-09 09:23:41 -06:00
|
|
|
|
|
|
|
// very much a hack job
|
|
|
|
func (rl *RepoList) MakeGoWork() error {
|
|
|
|
goSrcDir := os.Getenv("REPO_WORK_PATH")
|
|
|
|
filename := filepath.Join(goSrcDir, "go.work")
|
|
|
|
|
|
|
|
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
fmt.Fprintln(f, "go 1.21.4") // fix this
|
|
|
|
fmt.Fprintln(f, "")
|
|
|
|
fmt.Fprintln(f, "use (")
|
2024-03-09 16:49:57 -06:00
|
|
|
|
|
|
|
keys := make([]string, 0, len(rl.allrepos))
|
|
|
|
|
|
|
|
for k := range rl.allrepos {
|
|
|
|
keys = append(keys, k)
|
|
|
|
}
|
|
|
|
sort.Strings(keys)
|
|
|
|
|
|
|
|
for _, k := range keys {
|
|
|
|
repo := rl.allrepos[k]
|
2024-03-09 09:23:41 -06:00
|
|
|
if repo.Status.GoPath() == "" {
|
|
|
|
// skip repos that aren't go
|
|
|
|
// todo: handle non-flat repos?
|
2024-03-09 22:02:53 -06:00
|
|
|
log.Info("SKIPPED REPO", repo.Status.Path())
|
2024-03-09 09:23:41 -06:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if repo.Status.Exists("go.mod") {
|
|
|
|
fmt.Fprintln(f, "\t"+repo.Status.GoPath())
|
2024-03-09 22:02:53 -06:00
|
|
|
log.Info("ADDING REPO", goSrcDir, repo.Status.GoPath())
|
2024-03-09 09:23:41 -06:00
|
|
|
} else {
|
2024-03-09 16:49:57 -06:00
|
|
|
log.Log(REPO, "missing go.mod for", repo.Status.Path())
|
|
|
|
// repo.Status.MakeRedomod()
|
2024-03-09 09:23:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Fprintln(f, ")")
|
|
|
|
return nil
|
|
|
|
}
|