repolist/scan.go

80 lines
1.7 KiB
Go
Raw Normal View History

2024-02-17 08:39:55 -06:00
package repolist
import (
"fmt"
"os/user"
"strings"
"go.wit.com/log"
)
2024-02-17 14:22:24 -06:00
func (r *RepoList) SetAutoScan(b bool) {
me.autoScan = b
}
func (r *RepoList) ScanRepositories() (int, string) {
2024-02-17 08:39:55 -06:00
var i int
2024-02-18 15:09:35 -06:00
t := TimeFunction(func() {
2024-02-17 08:39:55 -06:00
for _, repo := range me.allrepos {
i += 1
2024-02-17 14:22:24 -06:00
repo.NewScan()
2024-02-17 08:39:55 -06:00
}
})
s := fmt.Sprint(t)
log.Info("Scanned", i, "repositories. todo: count/show changes", s)
return i, s
}
2024-02-17 14:22:24 -06:00
func (r *Repo) NewScan() bool {
2024-02-17 15:48:56 -06:00
if r.Status == nil {
log.Warn("repo.Status = nil. not initialized for some reason")
2024-02-17 08:39:55 -06:00
return false
}
// first run the repostatus update
2024-02-17 15:48:56 -06:00
r.Status.UpdateNew()
2024-02-17 08:39:55 -06:00
// now read those values and display them in our table
2024-02-17 15:48:56 -06:00
mname := r.Status.GetMasterBranchName()
mver := r.Status.GetMasterVersion()
2024-02-17 08:39:55 -06:00
mver = mver + " (" + mname + ")"
r.masterVersion.SetLabel(mver)
2024-02-17 15:48:56 -06:00
dname := r.Status.GetDevelBranchName()
dver := r.Status.GetDevelVersion()
2024-02-17 08:39:55 -06:00
if dname != "devel" {
dver = dver + " (" + dname + ")"
}
r.develVersion.SetLabel(dver)
2024-02-17 15:48:56 -06:00
uname := r.Status.GetUserBranchName()
uver := r.Status.GetUserVersion()
2024-02-17 08:39:55 -06:00
usr, _ := user.Current()
if uname != usr.Username {
uver = uver + " (" + uname + ")"
}
r.userVersion.SetLabel(uver)
2024-02-17 15:48:56 -06:00
cbname := r.Status.GetCurrentBranchName()
cbversion := r.Status.GetCurrentBranchVersion()
lasttag := r.Status.GetLastTagVersion()
2024-02-17 08:39:55 -06:00
r.lastTag.SetLabel(lasttag)
r.vLabel.SetLabel(cbname + " " + cbversion)
2024-02-17 15:48:56 -06:00
if c, ok := r.Status.Changed(); ok {
2024-02-17 08:39:55 -06:00
c := strings.TrimSpace(c)
for _, line := range strings.Split(c, "\n") {
2024-02-17 15:48:56 -06:00
log.Info(r.Status.Path(), line)
2024-02-17 08:39:55 -06:00
}
}
2024-02-17 15:48:56 -06:00
status := r.Status.GetStatus()
2024-02-17 08:39:55 -06:00
r.dirtyLabel.SetLabel(status)
if status == "PERFECT" {
if me.autoHidePerfect {
r.Hide()
}
return true
}
return false
}