161 lines
3.8 KiB
Go
161 lines
3.8 KiB
Go
// This is a simple example
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/lib/gui/repostatus"
|
|
)
|
|
|
|
func (r *repo) newScan() bool {
|
|
if r.status == nil {
|
|
log.Warn("repo.status = nil. not initialized for some reason")
|
|
return false
|
|
}
|
|
// r.scan()
|
|
if repostatus.VerifyLocalGoRepo(r.getPath()) {
|
|
log.Verbose("repo actually exists", r.getPath())
|
|
} else {
|
|
log.Warn("repo does not exist", r.getPath())
|
|
return false
|
|
}
|
|
|
|
cbname := r.status.GetCurrentBranchName()
|
|
cbversion := r.status.GetCurrentBranchVersion()
|
|
lasttag := r.status.GetLastTagVersion()
|
|
r.lastTag.SetLabel(lasttag)
|
|
r.vLabel.SetLabel(cbname + " " + cbversion)
|
|
|
|
if r.status.Changed() {
|
|
log.Warn("should scan here")
|
|
}
|
|
status := r.status.GetStatus()
|
|
r.dirtyLabel.SetLabel(status)
|
|
if status == "PERFECT" {
|
|
if me.autoHidePerfect.Checked() {
|
|
r.Hide()
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (r *repo) getGoSumStatus() string {
|
|
return r.goSumStatus.String()
|
|
}
|
|
|
|
func (r *repo) setGoSumStatus(s string) {
|
|
r.goSumStatus.SetLabel(s)
|
|
r.status.SetGoSumStatus(s)
|
|
}
|
|
|
|
func (r *repo) checkDirty() bool {
|
|
if r.status.CheckDirty() {
|
|
log.Info("dirty repo:", r.status.String(), r.getGoSumStatus())
|
|
r.setGoSumStatus("DIRTY")
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (r *repo) checkSafeGoSumRemake() {
|
|
if ok, bad := r.status.CheckSafeGoSumRemake(); ok {
|
|
log.Info("checkSafeGoSumRemake() is safe to redo")
|
|
r.setGoSumStatus("SAFE")
|
|
r.status.MakeRedomod()
|
|
} else {
|
|
log.Info("checkSafeGoSumRemake() is not safe. problems:", bad)
|
|
r.setGoSumStatus("BAD DEP")
|
|
}
|
|
}
|
|
|
|
func scanGoSum() {
|
|
for _, repo := range me.allrepos {
|
|
if repo.String() == "go.wit.com/apps/guireleaser" {
|
|
if release.guireleaser == nil {
|
|
release.guireleaser = repo
|
|
}
|
|
}
|
|
latestversion := repo.status.GetLastTagVersion()
|
|
if repo.getGoSumStatus() == "BAD" {
|
|
continue
|
|
}
|
|
if repo.getGoSumStatus() == "DIRTY" {
|
|
continue
|
|
}
|
|
if repo.status.CheckPrimativeGoMod() {
|
|
log.Info("PRIMATIVE repo:", latestversion, repo.status.String())
|
|
repo.setGoSumStatus("PRIMATIVE")
|
|
continue
|
|
}
|
|
if repo.checkDirty() {
|
|
log.Info("dirty repo:", latestversion, repo.status.String())
|
|
log.Info("dirty repo.getGoSumStatus =", repo.getGoSumStatus())
|
|
repo.setGoSumStatus("DIRTY")
|
|
|
|
// release.repo.SetValue(repo.status.String())
|
|
// release.status.SetValue("dirty")
|
|
// release.notes.SetValue("You must commit your changes\nbefore you can continue")
|
|
// release.current = repo
|
|
// release.openrepo.Enable()
|
|
continue
|
|
}
|
|
if ok, missing := repo.status.CheckGoSum(); ok {
|
|
log.Info("repo has go.sum requirements that are clean")
|
|
repo.setGoSumStatus("CLEAN")
|
|
} else {
|
|
log.Info("repo has go.sum requirements that are screwed up. missing:", missing)
|
|
repo.setGoSumStatus("BAD")
|
|
|
|
// release.repo.SetValue(repo.status.String())
|
|
// release.status.SetValue("bad")
|
|
// release.notes.SetValue("the go.sum file is wrong")
|
|
// release.current = repo
|
|
// release.openrepo.Enable()
|
|
continue
|
|
}
|
|
status := repo.dirtyLabel.String()
|
|
if status == "PERFECT" {
|
|
continue
|
|
} else {
|
|
repo.status.UpdateCurrent()
|
|
repo.newScan()
|
|
}
|
|
|
|
log.Info("repo:", latestversion, status, repo.status.String())
|
|
}
|
|
log.Info("scanGoSum() 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()
|
|
}
|
|
}
|
|
}
|