autotypist/releaseWindow.go

330 lines
8.7 KiB
Go
Raw Normal View History

// This is a simple example
package main
import (
"go.wit.com/gui"
"go.wit.com/log"
"go.wit.com/lib/gadgets"
)
var release releaseStruct
type releaseStruct struct {
current *repo
win *gadgets.BasicWindow
box *gui.Node
group *gui.Node
grid *gui.Node
repo *gadgets.OneLiner
status *gadgets.OneLiner
notes *gadgets.OneLiner
version *gadgets.OneLiner
reason *gadgets.OneLiner
openrepo *gui.Node
goGetB *gui.Node
checkGoSumB *gui.Node
checkDirtyB *gui.Node
makeRedomodB *gui.Node
sendVersionB *gui.Node
}
func createReleaseWindow() {
if release.win != nil {
release.win.Toggle()
return
}
release.win = gadgets.NewBasicWindow(me.myGui, "Make a new release")
release.win.Custom = func() {
log.Info("Release Window close")
}
release.win.Make()
release.win.StandardClose()
release.win.Draw()
release.box = release.win.Box()
release.group = release.box.NewGroup("things")
release.grid = release.group.NewGrid("buildOptions", 2, 1)
// do an initial scan of all the repos
scanGoSum()
release.grid.NewButton("next repo", func() {
log.Info("find the next repo to release here")
if findNextDirty() {
log.Info("found a dirty repo")
} else {
findNextRepo()
}
findDirty2()
})
release.openrepo = release.grid.NewButton("open repo", func() {
if release.current == nil {
log.Info("find the next repo first")
return
}
if ok, missing := release.current.status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean")
release.status.SetValue("CLEAN")
release.current.goSumStatus.SetValue("CLEAN")
} else {
log.Info("BAD repo has go.sum requirements that are screwed up. missing:", missing)
release.status.SetValue("BAD")
release.current.goSumStatus.SetValue("BAD")
}
release.current.status.Update()
release.current.newScan()
if release.current.dirtyLabel.String() == "PERFECT" {
return
}
// log.Info("find the next repo to release here")
release.current.status.Toggle()
})
release.openrepo.Disable()
release.repo = gadgets.NewOneLiner(release.grid, "repo")
release.status = gadgets.NewOneLiner(release.grid, "status")
release.notes = gadgets.NewOneLiner(release.grid, "notes")
release.version = gadgets.NewOneLiner(release.grid, "version")
release.version.SetValue("0.13.11")
release.reason = gadgets.NewOneLiner(release.grid, "reason")
release.reason.SetValue("release automation")
release.sendVersionB = release.grid.NewButton("send version", func() {
log.Info("set version()")
release.current.status.SetVersion("0", "13", "11", "release automation")
})
release.grid.NewButton("set ignore", func() {
tmp := release.current.goSumStatus.String()
log.Info("trying to set repo IGNORE is now =", tmp)
release.current.goSumStatus.SetValue("IGNORE")
release.current.goSumStatus.SetLabel("IGNORE")
release.current.goSumStatus.SetText("IGNORE")
})
release.checkDirtyB = release.grid.NewButton("CheckDirty()", func() {
buttonDisable()
if release.current.status.CheckDirty() {
log.Info("repo is dirty")
} else {
log.Info("repo is not dirty")
}
buttonEnable()
})
release.checkGoSumB = release.grid.NewButton("CheckGoSum()", func() {
buttonDisable()
tmp := release.current.String()
log.Info("Run CheckGoSum on repo:", tmp)
if ok, missing := release.current.status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean")
release.current.goSumStatus.SetValue("CLEAN")
release.current.goSumStatus.SetLabel("CLEAN")
release.current.goSumStatus.SetText("CLEAN")
} else {
if missing == "" {
log.Info("BAD VERSION repo has go.sum requirements that are screwed up.", tmp)
if release.current.goSumStatus.String() == "BAD" {
release.current.goSumStatus.SetLabel("BAD VERSION")
release.current.goSumStatus.SetText("BAD VERSION")
}
} else {
log.Info("BAD VERSION repo has go.sum requirements that are screwed up.", tmp)
log.Info("BAD VERSION need to addRepo() the missing repo", missing)
// addRepo(reposgrid, missing, "master", "master", "master")
}
}
buttonEnable()
})
release.grid.NewButton("CheckPrimativeGoMod()", func() {
tmp := release.current.String()
log.Info("Run CheckGoSum on repo:", tmp)
if release.current.status.CheckPrimativeGoMod() {
log.Info("repo has PRIMATIVE go.mod")
} else {
log.Info("repo go.mod requies checking for a go.sum")
}
})
release.grid.NewButton("reset with scanGoSum()", func() {
buttonDisable()
// do an initial scan of all the repos
scanGoSum()
buttonEnable()
})
release.makeRedomodB = release.grid.NewButton("make redomod", func() {
buttonDisable()
release.current.status.MakeRedomod()
buttonEnable()
})
release.goGetB = release.grid.NewButton("go get -v -u .", func() {
buttonDisable()
err, output := release.current.status.RunCmd([]string{"go", "get", "-v", "-u", "."})
log.Warn(output)
if err == nil {
log.Warn("go get worked. recheck go.sum")
} else {
log.Warn("go get failed")
}
buttonEnable()
})
}
func buttonDisable() {
release.goGetB.Disable()
release.makeRedomodB.Disable()
release.checkGoSumB.Disable()
release.openrepo.Disable()
release.checkDirtyB.Disable()
release.sendVersionB.Disable()
}
func buttonEnable() {
release.goGetB.Enable()
release.makeRedomodB.Enable()
release.checkGoSumB.Enable()
release.openrepo.Enable()
release.checkDirtyB.Enable()
release.sendVersionB.Enable()
}
func findDirty2() bool {
for _, repo := range me.allrepos {
goSumS := repo.goSumStatus.String()
dirtyS := repo.dirtyLabel.String()
if goSumS == "IGNORE" {
continue
}
if goSumS == "DIRTY 2" {
log.Info("repo DIRTY 2", repo.String(), goSumS, dirtyS)
release.repo.SetValue(repo.status.String())
release.status.SetValue("dirty 2")
release.notes.SetValue("check dirty 2 manually")
release.current = repo
release.openrepo.Enable()
return true
} else {
log.Info("repo not DIRTY 2", repo.String(), goSumS, dirtyS)
}
}
return false
}
func findNextDirty() bool {
for _, repo := range me.allrepos {
goSumS := repo.goSumStatus.String()
dirtyS := repo.dirtyLabel.String()
log.Info("repo", repo.String(), goSumS, dirtyS)
if goSumS == "PRIMATIVE" {
continue
}
if goSumS == "IGNORE" {
continue
}
if goSumS == "DIRTY 2" {
continue
}
// latestversion := repo.status.GetLastTagVersion()
if goSumS == "CLEAN" {
if dirtyS == "PERFECT" {
continue
}
release.repo.SetValue(repo.status.String())
release.status.SetValue("clean")
release.notes.SetValue("check manually")
release.current = repo
release.openrepo.Enable()
return true
}
if goSumS == "DIRTY" {
if ok, missing := repo.status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean")
// repo.goSumStatus.SetLabel("CLEAN")
} else {
log.Info("DIRTY 2 repo has go.sum requirements that are screwed up. missing:", missing)
repo.goSumStatus.SetLabel("DIRTY 2")
continue
}
// release.repo.SetValue(repo.status.String())
// release.status.SetValue("bad")
release.repo.SetValue(repo.status.String())
release.status.SetValue("dirty")
release.notes.SetValue("commit changes")
release.current = repo
release.openrepo.Enable()
return true
}
}
log.Info("tried to findNextDirty() but not sure what to do next")
return false
}
func findNextRepo() {
for _, repo := range me.allrepos {
goSumS := repo.goSumStatus.String()
dirtyS := repo.dirtyLabel.String()
log.Info("repo", repo.String(), goSumS, dirtyS)
if goSumS == "IGNORE" {
continue
}
if goSumS == "DIRTY 2" {
continue
}
if goSumS == "BAD VERSION" {
continue
}
// latestversion := repo.status.GetLastTagVersion()
if goSumS == "CLEAN" {
if dirtyS == "PERFECT" {
continue
}
release.repo.SetValue(repo.status.String())
release.status.SetValue("clean")
release.notes.SetValue("check manually")
release.current = repo
release.openrepo.Enable()
return
}
if goSumS == "DIRTY" {
if ok, missing := repo.status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean")
// repo.goSumStatus.SetLabel("CLEAN")
} else {
log.Info("DIRTY 3 repo has go.sum requirements that are screwed up. missing:", missing)
repo.goSumStatus.SetLabel("DIRTY 3")
continue
}
// release.repo.SetValue(repo.status.String())
// release.status.SetValue("bad")
release.repo.SetValue(repo.status.String())
release.status.SetValue("dirty")
release.notes.SetValue("commit changes")
release.current = repo
release.openrepo.Enable()
return
}
if goSumS == "BAD" {
release.repo.SetValue(repo.status.String())
release.status.SetValue("bad")
release.notes.SetValue("redo go.sum")
release.current = repo
release.openrepo.Enable()
return
}
}
log.Info("tried to findNextRepo() but not sure what to do next")
}