repolist/scan.go

114 lines
2.4 KiB
Go
Raw 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
"strings"
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
}
2024-02-17 14:22:24 -06:00
func (r *RepoList) ScanRepositories() (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
2024-02-23 14:25:00 -06:00
changed := repo.NewScan()
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
}
2024-02-23 14:25:00 -06:00
func (r *RepoRow) NewScan() int {
var changed int = 0
2024-02-17 15:48:56 -06:00
if r.Status == nil {
2024-02-29 09:16:20 -06:00
log.Log(REPOWARN, "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
}
// run the repostatus update
2024-02-20 14:45:09 -06:00
r.Status.Update()
2024-02-17 08:39:55 -06:00
if r.lastTag != nil {
if r.pb != nil {
r.lastTag.SetLabel(r.pb.GetLastTag())
} else {
log.Info("r.pb was nil")
}
}
2024-11-29 02:01:43 -06:00
if r.masterVersion == nil {
panic("what the fuck node")
}
2024-11-29 02:01:43 -06:00
if r.pb == nil {
panic("what the fuck pb")
}
2024-12-01 15:10:33 -06:00
r.masterVersion.SetLabel(r.pb.GetMasterVersion())
r.develVersion.SetLabel(r.pb.GetDevelVersion())
r.userVersion.SetLabel(r.pb.GetUserVersion())
r.gitState.SetLabel(r.Status.GitState())
r.currentName.SetLabel(r.Status.GetCurrentBranchName())
r.currentVersion.SetLabel(r.Status.GetCurrentBranchVersion())
if r.Status.GitState() == "PERFECT" {
r.Hide()
2024-11-30 15:07:27 -06:00
} else {
r.Show()
}
2024-11-29 02:01:43 -06:00
/*
tags := []string{"%(objectname)", "%(creatordate)", "%(*authordate)", "%(refname)", "%(subject)"}
format := strings.Join(tags, "_,,,_")
cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format}
// log.Info("RUNNING:", strings.Join(cmd, " "))
result := r.pb.RunQuiet(cmd)
if result.Error != nil {
log.Warn("git for-each-ref error:", result.Error)
}
for i, line := range result.Stdout {
log.Info(i, line)
}
if me.hideFunction == nil {
// application didn't register a hide function
// always show everything in that case
r.Show()
} else {
me.hideFunction(r)
}
*/
2024-02-25 13:10:23 -06:00
// print out whatever changes have happened
2024-02-17 15:48:56 -06:00
if c, ok := r.Status.Changed(); ok {
2024-02-24 11:55:29 -06:00
log.Log(REPOWARN, "something finally changed")
2024-02-17 08:39:55 -06:00
c := strings.TrimSpace(c)
for _, line := range strings.Split(c, "\n") {
2024-02-29 09:16:20 -06:00
log.Log(REPOWARN, r.Status.Path(), line)
2024-02-23 14:25:00 -06:00
changed += 1
2024-02-17 08:39:55 -06:00
}
}
2024-02-18 17:56:25 -06:00
2024-02-23 14:25:00 -06:00
return changed
2024-02-17 08:39:55 -06:00
}