repolist/scan.go

113 lines
2.3 KiB
Go

package repolist
import (
"fmt"
"strconv"
"strings"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func (r *RepoList) RegisterHideFunction(f func(*RepoRow)) {
me.hideFunction = f
}
func (r *RepoList) ScanRepositories() (int, string) {
var i int
var shown int
var total int
t := TimeFunction(func() {
for _, repo := range me.allrepos {
i += 1
changed := repo.NewScan()
total += changed
}
var hidden int
for _, repo := range me.allrepos {
if repo.Hidden() {
hidden += 1
} else {
shown += 1
}
}
})
s := fmt.Sprint(t)
tmp := strconv.Itoa(shown) + " repos shown"
me.shownCount.SetText(tmp)
me.duration.SetText(s)
log.Info("repolist Scanned", i, "repositories.", total, "changes in", s)
return i, s
}
func (r *RepoRow) NewScan() int {
return r.NewScan2()
}
func (r *RepoRow) UpdatePb(newpb *gitpb.Repo) {
r.pb = newpb
}
func (r *RepoRow) NewScan3(newpb *gitpb.Repo) int {
if newpb.GetMasterVersion() != r.pb.GetMasterVersion() {
log.Info("THIS IS IT", newpb.GetMasterVersion(), r.pb.GetMasterVersion(), newpb.GetGoPath())
}
r.pb = newpb
return r.NewScan2()
}
func (r *RepoRow) NewScan2() int {
var changed int = 0
if r.Status == nil {
log.Log(REPOWARN, "repo.Status = nil. not initialized for some reason")
return changed
}
pb := r.pb
if pb == nil {
log.Log(REPOWARN, "NewScan() pb = nil")
return changed
}
// run the repostatus update
r.Status.Update()
if r.lastTag != nil {
r.lastTag.SetLabel(pb.GetLastTag())
}
if r.masterVersion == nil {
panic("what the fuck node")
}
if r.pb == nil {
panic("what the fuck pb")
}
r.masterVersion.SetLabel(pb.GetMasterVersion())
r.develVersion.SetLabel(pb.GetDevelVersion())
r.userVersion.SetLabel(pb.GetUserVersion())
r.gitState.SetLabel(r.Status.GitState())
r.currentName.SetLabel(pb.GetCurrentBranchName())
r.currentVersion.SetLabel(pb.GetCurrentBranchVersion())
if r.State() == "merge to main" {
r.Hide()
}
if r.Status.GitState() == "PERFECT" {
r.Hide()
} else {
r.Show()
}
// print out whatever changes have happened
if c, ok := r.Status.Changed(); ok {
log.Log(REPOWARN, "something finally changed")
c := strings.TrimSpace(c)
for _, line := range strings.Split(c, "\n") {
log.Log(REPOWARN, r.Status.Path(), line)
changed += 1
}
}
return changed
}