repolist/scan.go

99 lines
1.9 KiB
Go
Raw Permalink Normal View History

2024-02-17 08:39:55 -06:00
package repolist
import (
"fmt"
2024-02-19 19:43:21 -06:00
"strconv"
2024-02-17 08:39:55 -06:00
2024-12-17 18:49:11 -06:00
"go.wit.com/lib/protobuf/gitpb"
2024-03-02 17:18:50 -06:00
"go.wit.com/log"
2024-02-17 08:39:55 -06:00
)
2024-02-23 09:02:51 -06:00
func (r *RepoList) RegisterHideFunction(f func(*RepoRow)) {
2024-02-19 19:43:21 -06:00
me.hideFunction = f
}
func (r *RepoList) ScanRepositoriesOld() (int, string) {
2024-02-17 08:39:55 -06:00
var i int
2024-02-19 19:43:21 -06:00
var shown int
2024-02-23 14:25:00 -06:00
var total 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
changed := repo.Update()
2024-02-23 14:25:00 -06:00
total += changed
2024-02-19 19:43:21 -06:00
}
var hidden int
for _, repo := range me.allrepos {
if repo.Hidden() {
hidden += 1
} else {
shown += 1
}
2024-02-17 08:39:55 -06:00
}
})
s := fmt.Sprint(t)
2024-02-19 19:43:21 -06:00
tmp := strconv.Itoa(shown) + " repos shown"
me.shownCount.SetText(tmp)
2024-02-20 14:45:09 -06:00
me.duration.SetText(s)
2024-02-19 19:43:21 -06:00
2024-11-30 15:07:27 -06:00
log.Info("repolist Scanned", i, "repositories.", total, "changes in", s)
2024-02-17 08:39:55 -06:00
return i, s
}
2025-01-07 06:15:09 -06:00
func (r *RepoRow) UpdatePb(newpb *gitpb.Repo) {
r.pb = newpb
}
func (r *RepoRow) Update() int {
2024-02-23 14:25:00 -06:00
var changed int = 0
2024-02-17 15:48:56 -06:00
if r.Status == nil {
2025-01-07 18:53:10 -06:00
log.Log(WARN, "repo.Status = nil. not initialized for some reason")
2024-02-23 14:25:00 -06:00
return changed
2024-02-17 08:39:55 -06:00
}
2025-01-07 05:58:33 -06:00
pb := r.pb
2024-12-17 18:49:11 -06:00
if pb == nil {
2025-01-07 18:53:10 -06:00
log.Log(WARN, "NewScan() pb = nil")
2024-12-17 18:49:11 -06:00
return changed
}
2024-02-17 08:39:55 -06:00
if r.lastTag != nil {
2024-12-17 18:49:11 -06:00
r.lastTag.SetLabel(pb.GetLastTag())
}
2025-01-07 20:35:43 -06:00
// run the repostatus update
// r.Status.Update()
2025-01-07 18:18:29 -06:00
2024-12-17 18:49:11 -06:00
r.masterVersion.SetLabel(pb.GetMasterVersion())
r.develVersion.SetLabel(pb.GetDevelVersion())
r.userVersion.SetLabel(pb.GetUserVersion())
2025-01-07 20:35:43 -06:00
r.pbState.SetLabel(pb.GetState())
2025-01-07 04:58:42 -06:00
r.currentName.SetLabel(pb.GetCurrentBranchName())
r.currentVersion.SetLabel(pb.GetCurrentBranchVersion())
// disable the commit button if the repo is not on the user branch
if pb.GetCurrentBranchName() == pb.GetUserBranchName() {
2025-02-09 13:32:01 -06:00
if r.pb.GetState() == "dirty" {
r.diff.Enable()
r.commitB.Enable()
} else {
r.diff.Disable()
r.commitB.Disable()
}
} else {
2025-02-09 13:32:01 -06:00
r.diff.Disable()
r.commitB.Disable()
}
// TODO: finally make this alot smarter
2024-12-17 06:36:28 -06:00
if r.State() == "merge to main" {
r.Hide()
}
2025-01-29 16:18:04 -06:00
if pb.GetState() == "PERFECT" {
r.Hide()
2024-11-30 15:07:27 -06:00
} else {
r.Show()
}
2024-02-23 14:25:00 -06:00
return changed
2024-02-17 08:39:55 -06:00
}