repolist/common.go

175 lines
3.2 KiB
Go
Raw Normal View History

2024-02-17 08:39:55 -06:00
package repolist
import (
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-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 {
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-29 21:57:33 -06:00
/*
2024-02-18 15:09:35 -06:00
// returns the state of the GO go.mod and go.sum files
// this is used to tell if they are valid and correctly reflect
// the versions of the other GUI packages
// at this point in time, there is _NO_ way to be check our
// be sure that anything will run with older versions
// because this are changing too often at this point
// TODO: revisit this in 2025 or 2026
2024-02-23 09:02:51 -06:00
func (r *RepoRow) GoState() string {
2024-02-18 17:56:25 -06:00
if r == nil {
log.Info("GoState() r == nil")
return "goState == nil"
}
if r.goState == nil {
log.Info("GoState() r.goState == nil")
return "goState == nil"
}
return r.goState.String()
2024-02-18 15:09:35 -06:00
}
2024-02-23 09:02:51 -06:00
func (r *RepoRow) SetGoState(s string) {
2024-02-18 17:56:25 -06:00
if r == nil {
log.Info("SetGoState() r == nil")
return
}
if r.goState == nil {
log.Info("goState == nil")
return
}
r.goState.SetText(s)
2024-02-18 15:09:35 -06:00
}
2024-02-29 21:57:33 -06:00
*/
2024-02-18 15:09:35 -06:00
2024-02-23 09:02:51 -06:00
func (r *RepoRow) IsPerfect() bool {
if r.gitState.String() == "PERFECT" {
2024-02-17 08:39:55 -06:00
return true
}
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-02-23 09:02:51 -06:00
func (r *RepoRow) RunCmd(cmd []string) (error, string) {
2024-02-17 15:48:56 -06:00
return r.Status.RunCmd(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
}