allow scan every minute

move go mod status into repostatus
    working on improving logic of which package to release next

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-26 02:04:19 -06:00
parent 4773d43cf6
commit 1f757d26ff
5 changed files with 102 additions and 29 deletions

View File

@ -53,6 +53,12 @@ func globalDisplayOptions(box *gui.Node) {
if release.win == nil { if release.win == nil {
log.Info("Creating the Release Window") log.Info("Creating the Release Window")
createReleaseWindow() createReleaseWindow()
for _, repo := range me.allrepos {
repo.status.Update()
repo.newScan()
}
// open the repo window
reposwin.Toggle()
log.Info("Toggling the Release Window") log.Info("Toggling the Release Window")
release.win.Toggle() release.win.Toggle()
} }
@ -93,6 +99,7 @@ func globalDisplayOptions(box *gui.Node) {
globalDisplayShow() globalDisplayShow()
} }
} }
me.scanEveryMinute = group1.NewCheckbox("Scan every minute").SetChecked(false)
group1.NewButton("status.Update() all", func() { group1.NewButton("status.Update() all", func() {
for _, repo := range me.allrepos { for _, repo := range me.allrepos {

33
main.go
View File

@ -3,8 +3,10 @@ package main
import ( import (
"embed" "embed"
"fmt"
"os/user" "os/user"
"strings" "strings"
"time"
"go.wit.com/log" "go.wit.com/log"
@ -28,9 +30,34 @@ func main() {
autotypistWindow() autotypistWindow()
repoworld() repoworld()
// keeps the app alive // scan repos every 30 seconds
// TODO: rescan the status of the repos every so often? // check every second for the checkbox changing
gui.Watchdog() var i int = 60
myTicker(1 * time.Second, "newScan()", func() {
i += 1
if ! me.scanEveryMinute.Checked() {
if i < 60 {
i = 60
}
// print every 13 seconds
if i%13 == 0 {
log.Info("Not auto scanning", i)
}
return
}
if i < 60 {
return
}
i = 0
duration := timeFunction(func() {
scanGoSum()
for _, repo := range me.allrepos {
repo.newScan()
}
})
s := fmt.Sprint(duration)
me.autoWorkingPwd.SetText(s)
})
} }
func addRepo(grid *gui.Node, path string, master string, devel string, user string) { func addRepo(grid *gui.Node, path string, master string, devel string, user string) {

View File

@ -75,11 +75,11 @@ func createReleaseWindow() {
if ok, missing := release.current.status.CheckGoSum(); ok { if ok, missing := release.current.status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean") log.Info("repo has go.sum requirements that are clean")
release.status.SetValue("CLEAN") release.status.SetValue("CLEAN")
release.current.goSumStatus.SetValue("CLEAN") release.current.setGoSumStatus("CLEAN")
} else { } else {
log.Info("BAD repo has go.sum requirements that are screwed up. missing:", missing) log.Info("BAD repo has go.sum requirements that are screwed up. missing:", missing)
release.status.SetValue("BAD") release.status.SetValue("BAD")
release.current.goSumStatus.SetValue("BAD") release.current.setGoSumStatus("BAD")
} }
if release.current.status.ReadOnly() { if release.current.status.ReadOnly() {
release.readOnly.SetValue("true") release.readOnly.SetValue("true")
@ -115,11 +115,9 @@ func createReleaseWindow() {
release.current.status.SetVersion("0", "13", "12", release.reason.String()) release.current.status.SetVersion("0", "13", "12", release.reason.String())
}) })
release.grid.NewButton("set ignore", func() { release.grid.NewButton("set ignore", func() {
tmp := release.current.goSumStatus.String() tmp := release.current.getGoSumStatus()
log.Info("trying to set repo IGNORE is now =", tmp) log.Info("trying to set repo IGNORE is now =", tmp)
release.current.goSumStatus.SetValue("IGNORE") release.current.setGoSumStatus("IGNORE")
release.current.goSumStatus.SetLabel("IGNORE")
release.current.goSumStatus.SetText("IGNORE")
}) })
release.checkDirtyB = release.grid.NewButton("CheckDirty()", func() { release.checkDirtyB = release.grid.NewButton("CheckDirty()", func() {
buttonDisable() buttonDisable()
@ -136,15 +134,12 @@ func createReleaseWindow() {
log.Info("Run CheckGoSum on repo:", tmp) log.Info("Run CheckGoSum on repo:", tmp)
if ok, missing := release.current.status.CheckGoSum(); ok { if ok, missing := release.current.status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean") log.Info("repo has go.sum requirements that are clean")
release.current.goSumStatus.SetValue("CLEAN") release.current.setGoSumStatus("CLEAN")
release.current.goSumStatus.SetLabel("CLEAN")
release.current.goSumStatus.SetText("CLEAN")
} else { } else {
if missing == "" { if missing == "" {
log.Info("BAD VERSION repo has go.sum requirements that are screwed up.", tmp) log.Info("BAD VERSION repo has go.sum requirements that are screwed up.", tmp)
if release.current.goSumStatus.String() == "BAD" { if release.current.getGoSumStatus() == "BAD" {
release.current.goSumStatus.SetLabel("BAD VERSION") release.current.setGoSumStatus("BAD VERSION")
release.current.goSumStatus.SetText("BAD VERSION")
} }
} else { } else {
log.Info("BAD VERSION repo has go.sum requirements that are screwed up.", tmp) log.Info("BAD VERSION repo has go.sum requirements that are screwed up.", tmp)
@ -230,7 +225,7 @@ func buttonEnable() {
func findDirty2() bool { func findDirty2() bool {
log.Info("findDirty2() START") log.Info("findDirty2() START")
for _, repo := range me.allrepos { for _, repo := range me.allrepos {
goSumS := repo.goSumStatus.String() goSumS := repo.getGoSumStatus()
dirtyS := repo.dirtyLabel.String() dirtyS := repo.dirtyLabel.String()
if goSumS == "IGNORE" { if goSumS == "IGNORE" {
@ -272,7 +267,7 @@ func setCurrentRepo(newcur *repo, s string, note string) bool {
func findNextDirty() bool { func findNextDirty() bool {
for _, repo := range me.allrepos { for _, repo := range me.allrepos {
goSumS := repo.goSumStatus.String() goSumS := repo.getGoSumStatus()
dirtyS := repo.dirtyLabel.String() dirtyS := repo.dirtyLabel.String()
log.Info("findNextDirty()", repo.String(), goSumS, dirtyS) log.Info("findNextDirty()", repo.String(), goSumS, dirtyS)
@ -303,10 +298,10 @@ func findNextDirty() bool {
if goSumS == "DIRTY" { if goSumS == "DIRTY" {
if ok, missing := repo.status.CheckGoSum(); ok { if ok, missing := repo.status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean") log.Info("repo has go.sum requirements that are clean")
// repo.goSumStatus.SetLabel("CLEAN") // repo.setGoSumStatus("CLEAN")
} else { } else {
log.Info("DIRTY 2 repo has go.sum requirements that are screwed up. missing:", missing) log.Info("DIRTY 2 repo has go.sum requirements that are screwed up. missing:", missing)
repo.goSumStatus.SetLabel("DIRTY 2") repo.setGoSumStatus("DIRTY 2")
continue continue
} }
@ -321,7 +316,7 @@ func findNextDirty() bool {
func findNextRepo() { func findNextRepo() {
for _, repo := range me.allrepos { for _, repo := range me.allrepos {
goSumS := repo.goSumStatus.String() goSumS := repo.getGoSumStatus()
dirtyS := repo.dirtyLabel.String() dirtyS := repo.dirtyLabel.String()
log.Info("findNextRepo()", repo.String(), goSumS, dirtyS) log.Info("findNextRepo()", repo.String(), goSumS, dirtyS)
@ -346,10 +341,10 @@ func findNextRepo() {
if goSumS == "DIRTY" { if goSumS == "DIRTY" {
if ok, missing := repo.status.CheckGoSum(); ok { if ok, missing := repo.status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean") log.Info("repo has go.sum requirements that are clean")
// repo.goSumStatus.SetLabel("CLEAN") // repo.setGoSumStatus("CLEAN")
} else { } else {
log.Info("DIRTY 3 repo has go.sum requirements that are screwed up. missing:", missing) log.Info("DIRTY 3 repo has go.sum requirements that are screwed up. missing:", missing)
repo.goSumStatus.SetLabel("DIRTY 3") repo.setGoSumStatus("DIRTY 3")
continue continue
} }

55
scan.go
View File

@ -2,6 +2,9 @@
package main package main
import ( import (
"fmt"
"time"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/lib/gui/repostatus" "go.wit.com/lib/gui/repostatus"
@ -74,24 +77,33 @@ func (r *repo) getStatus() string {
return "merge" return "merge"
} }
func (r *repo) getGoSumStatus() string {
return r.goSumStatus.String()
}
func (r *repo) setGoSumStatus(s string) {
r.goSumStatus.SetLabel(s)
r.status.SetGoSumStatus(s)
}
func scanGoSum() { func scanGoSum() {
for _, repo := range me.allrepos { for _, repo := range me.allrepos {
latestversion := repo.status.GetLastTagVersion() latestversion := repo.status.GetLastTagVersion()
if repo.goSumStatus.String() == "BAD" { if repo.getGoSumStatus() == "BAD" {
continue continue
} }
if repo.goSumStatus.String() == "DIRTY" { if repo.getGoSumStatus() == "DIRTY" {
continue continue
} }
if repo.status.CheckPrimativeGoMod() { if repo.status.CheckPrimativeGoMod() {
log.Info("PRIMATIVE repo:", latestversion, repo.status.String()) log.Info("PRIMATIVE repo:", latestversion, repo.status.String())
repo.goSumStatus.SetLabel("PRIMATIVE") repo.setGoSumStatus("PRIMATIVE")
continue continue
} }
if repo.status.CheckDirty() { if repo.status.CheckDirty() {
log.Info("dirty repo:", latestversion, repo.status.String()) log.Info("dirty repo:", latestversion, repo.status.String())
log.Info("dirty repo.goSumStatus =", repo.goSumStatus.String()) log.Info("dirty repo.getGoSumStatus =", repo.getGoSumStatus())
repo.goSumStatus.SetLabel("DIRTY") repo.setGoSumStatus("DIRTY")
// release.repo.SetValue(repo.status.String()) // release.repo.SetValue(repo.status.String())
// release.status.SetValue("dirty") // release.status.SetValue("dirty")
@ -102,10 +114,10 @@ func scanGoSum() {
} }
if ok, missing := repo.status.CheckGoSum(); ok { if ok, missing := repo.status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean") log.Info("repo has go.sum requirements that are clean")
repo.goSumStatus.SetLabel("CLEAN") repo.setGoSumStatus("CLEAN")
} else { } else {
log.Info("repo has go.sum requirements that are screwed up. missing:", missing) log.Info("repo has go.sum requirements that are screwed up. missing:", missing)
repo.goSumStatus.SetLabel("BAD") repo.setGoSumStatus("BAD")
// release.repo.SetValue(repo.status.String()) // release.repo.SetValue(repo.status.String())
// release.status.SetValue("bad") // release.status.SetValue("bad")
@ -127,3 +139,32 @@ func scanGoSum() {
} }
log.Info("scan() did everything, not sure what to do next") log.Info("scan() did everything, not sure what to do next")
} }
// timeFunction takes a function as an argument and returns the execution time.
func timeFunction(f func()) time.Duration {
startTime := time.Now() // Record the start time
f() // Execute the function
return time.Since(startTime) // Calculate the elapsed time
}
func myTicker(t time.Duration, name string, f func()) {
ticker := time.NewTicker(t)
defer ticker.Stop()
done := make(chan bool)
/*
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
*/
for {
select {
case <-done:
fmt.Println("Done!")
return
case t := <-ticker.C:
log.Verbose(name, "Current time: ", t)
f()
}
}
}

View File

@ -49,6 +49,9 @@ type autoType struct {
// checkbox for --dry-run // checkbox for --dry-run
autoDryRun *gui.Node autoDryRun *gui.Node
// checkbox for intermittent scanning
scanEveryMinute *gui.Node
// The current working directory // The current working directory
autoWorkingPwd *gadgets.OneLiner autoWorkingPwd *gadgets.OneLiner