2024-01-09 15:34:53 -06:00
|
|
|
package repostatus
|
|
|
|
|
|
|
|
import (
|
2024-01-10 00:15:27 -06:00
|
|
|
"strconv"
|
2024-01-10 18:18:01 -06:00
|
|
|
"strings"
|
2024-01-10 00:15:27 -06:00
|
|
|
|
2024-01-09 15:34:53 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-11 15:56:50 -06:00
|
|
|
"go.wit.com/gui/gui"
|
2024-01-09 15:34:53 -06:00
|
|
|
"go.wit.com/gui/gadgets"
|
|
|
|
)
|
|
|
|
|
|
|
|
// creates the actual widgets.
|
|
|
|
// it's assumed you are always passing in a box
|
|
|
|
func draw(rs *RepoStatus) {
|
|
|
|
if ! rs.Ready() {return}
|
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
// display the status of the git repository
|
|
|
|
rs.drawGitStatus()
|
2024-01-09 15:34:53 -06:00
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
// display the git branches and options
|
|
|
|
rs.drawGitBranches()
|
2024-01-09 15:34:53 -06:00
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
// show standard git commit and merge controls
|
|
|
|
rs.drawGitCommands()
|
2024-01-09 15:34:53 -06:00
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
// figure out what the state of the git repository is
|
|
|
|
rs.Update()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) drawGitBranches() {
|
|
|
|
rs.gitBranchesGroup = rs.window.Box().NewGroup("branches")
|
|
|
|
newgrid := rs.gitBranchesGroup.NewGrid("gridnuts", 2, 2)
|
|
|
|
|
|
|
|
rs.masterDrop = gadgets.NewBasicDropdown(newgrid, "main branch")
|
|
|
|
rs.develDrop = gadgets.NewBasicDropdown(newgrid, "devel branch")
|
|
|
|
rs.userDrop = gadgets.NewBasicDropdown(newgrid, "user branch")
|
|
|
|
var master = ""
|
|
|
|
all := rs.getBranches()
|
|
|
|
for _, branch := range all {
|
|
|
|
log.Warn("getBranches()", branch)
|
|
|
|
rs.masterDrop.Add(branch)
|
|
|
|
rs.develDrop.Add(branch)
|
|
|
|
rs.userDrop.Add(branch)
|
|
|
|
if branch == "master" {
|
|
|
|
master = "master"
|
|
|
|
}
|
|
|
|
if branch == "main" {
|
|
|
|
master = "main"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rs.masterDrop.Set(master)
|
|
|
|
// relabel the various gadgets with the right branch name
|
2024-01-13 20:30:33 -06:00
|
|
|
rs.masterBranchVersion.SetLabel(master)
|
2024-01-11 15:56:50 -06:00
|
|
|
rs.major.SetTitle(master)
|
|
|
|
|
|
|
|
rs.develDrop.Set("devel")
|
|
|
|
rs.userDrop.Set("jcarr")
|
|
|
|
|
|
|
|
var count *gui.Node
|
|
|
|
|
2024-01-13 20:30:33 -06:00
|
|
|
rs.showBranchesButton = newgrid.NewButton("show branches", func() {
|
2024-01-11 15:56:50 -06:00
|
|
|
all := rs.getBranches()
|
|
|
|
i := len(all)
|
2024-01-11 23:24:09 -06:00
|
|
|
count.Set(strconv.Itoa(i) + " branches")
|
2024-01-11 15:56:50 -06:00
|
|
|
})
|
|
|
|
count = newgrid.NewLabel("")
|
2024-01-11 23:24:09 -06:00
|
|
|
|
2024-01-13 20:30:33 -06:00
|
|
|
rs.checkBranchesButton = newgrid.NewButton("check branches", func() {
|
|
|
|
if rs.CheckBranches() {
|
2024-01-11 23:24:09 -06:00
|
|
|
log.Warn("Branches are perfect")
|
|
|
|
} else {
|
|
|
|
log.Warn("Branches are not perfect")
|
2024-01-11 15:56:50 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) drawGitStatus() {
|
|
|
|
rs.gitStatusGroup = rs.window.Box().NewGroup("What GO Knows It Has")
|
|
|
|
newgrid := rs.gitStatusGroup.NewGrid("gridnuts", 2, 2)
|
2024-01-13 20:30:33 -06:00
|
|
|
// newgrid.SetNext(1,1)
|
2024-01-11 15:56:50 -06:00
|
|
|
newgrid.Margin()
|
|
|
|
newgrid.Pad()
|
|
|
|
|
|
|
|
rs.path = gadgets.NewOneLiner(newgrid, "path")
|
|
|
|
rs.currentBranch = gadgets.NewOneLiner(newgrid, "branch")
|
|
|
|
rs.lasttag = gadgets.NewOneLiner(newgrid, "last tag")
|
|
|
|
rs.currentVersion = gadgets.NewOneLiner(newgrid, "Version")
|
|
|
|
rs.tagsDrop = gadgets.NewBasicDropdown(newgrid, "existing tags")
|
2024-01-13 20:30:33 -06:00
|
|
|
rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master")
|
|
|
|
rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel")
|
|
|
|
rs.jcarrBranchVersion = gadgets.NewOneLiner(newgrid, "jcarr")
|
2024-01-11 15:56:50 -06:00
|
|
|
|
|
|
|
rs.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty")
|
|
|
|
|
|
|
|
rs.speed = gadgets.NewOneLiner(newgrid, "refresh speed =")
|
|
|
|
rs.speedActual = gadgets.NewOneLiner(newgrid, "speed actual =")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) drawGitCommands() {
|
|
|
|
rs.gitCommandsGroup = rs.window.Box().NewGroup("git commands")
|
|
|
|
newgrid := rs.gitCommandsGroup.NewGrid("gridnuts", 2, 2)
|
2024-01-10 18:18:01 -06:00
|
|
|
|
|
|
|
newgrid.NewButton("update", func() {
|
2024-01-09 15:34:53 -06:00
|
|
|
rs.Update()
|
|
|
|
})
|
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
label := "merge devel to " + rs.masterDrop.Get()
|
|
|
|
rs.develMerge = newgrid.NewButton(label, func() {
|
|
|
|
master := rs.masterDrop.Get()
|
|
|
|
rs.checkoutBranch("master", master)
|
|
|
|
if rs.getCurrentBranchName() != master {
|
2024-01-09 19:22:16 -06:00
|
|
|
log.Warn("something went wrong switching to the master branch. full stop!")
|
|
|
|
return
|
|
|
|
}
|
2024-01-11 23:24:09 -06:00
|
|
|
if ! rs.runGitCommands() {
|
2024-01-11 15:56:50 -06:00
|
|
|
log.Warn("SOMETHING WENT WRONG")
|
2024-01-11 23:24:09 -06:00
|
|
|
return
|
2024-01-11 15:56:50 -06:00
|
|
|
}
|
2024-01-09 19:22:16 -06:00
|
|
|
rs.develMerge.Disable() // don't let this run twice for now
|
2024-01-11 23:24:09 -06:00
|
|
|
rs.Update()
|
|
|
|
log.Warn("THINGS SEEM OK")
|
2024-01-09 19:22:16 -06:00
|
|
|
})
|
2024-01-10 18:18:01 -06:00
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
rs.major = gadgets.NewBasicCombobox(newgrid, "major")
|
2024-01-10 18:18:01 -06:00
|
|
|
rs.major.Custom = func () {
|
|
|
|
rs.setTag()
|
|
|
|
rs.generateCmd()
|
|
|
|
}
|
|
|
|
rs.minor = gadgets.NewBasicCombobox(newgrid, "minor")
|
|
|
|
rs.minor.Custom = func () {
|
|
|
|
rs.setTag()
|
|
|
|
rs.generateCmd()
|
|
|
|
}
|
|
|
|
rs.revision = gadgets.NewBasicCombobox(newgrid, "revision")
|
|
|
|
rs.revision.Custom = func () {
|
|
|
|
rs.setTag()
|
|
|
|
rs.generateCmd()
|
|
|
|
}
|
|
|
|
newgrid.NewLabel("new tag version")
|
|
|
|
rs.newversion = newgrid.NewLabel("3.1.4")
|
|
|
|
|
|
|
|
rs.versionMessage = gadgets.NewBasicEntry(newgrid, "tag message")
|
|
|
|
rs.versionMessage.Custom = func () {
|
|
|
|
rs.generateCmd()
|
|
|
|
}
|
|
|
|
rs.versionCmdOutput = gadgets.NewOneLiner(newgrid, "tag cmd")
|
|
|
|
|
|
|
|
rs.releaseVersion = newgrid.NewButton("tag and release new version", func() {
|
|
|
|
if ! rs.generateCmd() {
|
|
|
|
log.Warn("something is wrong. fix the errors first")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Warn("COMMIT IT HERE")
|
2024-01-11 23:24:09 -06:00
|
|
|
if ! rs.runGitCommands() {
|
2024-01-11 15:56:50 -06:00
|
|
|
log.Warn("SOMETHING WENT WRONG")
|
|
|
|
}
|
2024-01-11 23:24:09 -06:00
|
|
|
rs.Update()
|
|
|
|
log.Warn("THINGS SEEM OK")
|
2024-01-09 19:22:16 -06:00
|
|
|
})
|
|
|
|
|
2024-01-10 18:18:01 -06:00
|
|
|
newgrid.Margin()
|
|
|
|
newgrid.Pad()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) setTag() bool {
|
|
|
|
lasttag := rs.lasttag.Get()
|
|
|
|
var major, minor, revision string
|
|
|
|
major, minor, revision = splitVersion(lasttag)
|
|
|
|
|
|
|
|
olda, _ := strconv.Atoi(major)
|
|
|
|
oldb, _ := strconv.Atoi(minor)
|
|
|
|
oldc, _ := strconv.Atoi(revision)
|
|
|
|
|
|
|
|
log.Warn("current version here", lasttag)
|
|
|
|
log.Warn("current release a,b,c =", major, minor, revision)
|
|
|
|
|
|
|
|
newa, _ := strconv.Atoi(rs.major.Get())
|
|
|
|
|
|
|
|
newver := strconv.Itoa(newa)
|
|
|
|
if newa < olda {
|
2024-01-11 23:24:09 -06:00
|
|
|
log.Warn("new version bad", newver, "vs old version", lasttag, "newa =", newa, "olda =", olda)
|
2024-01-10 18:18:01 -06:00
|
|
|
rs.newversion.Set("bad")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if newa > olda {
|
|
|
|
log.Warn("new version ok", newver, "vs old version", lasttag)
|
|
|
|
rs.newversion.Set(newver)
|
|
|
|
rs.minor.Set("")
|
|
|
|
rs.revision.Set("")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-11 23:24:09 -06:00
|
|
|
newb, _ := strconv.Atoi(rs.minor.Get())
|
2024-01-10 18:18:01 -06:00
|
|
|
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb)
|
|
|
|
if newb < oldb {
|
2024-01-11 23:24:09 -06:00
|
|
|
log.Warn("new version bad", newver, "vs old version", lasttag, "newb =", newb, "oldb =", oldb)
|
2024-01-10 18:18:01 -06:00
|
|
|
rs.newversion.Set("bad")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if newb > oldb {
|
|
|
|
log.Warn("new version ok", newver, "vs old version", lasttag)
|
|
|
|
rs.newversion.Set(newver)
|
|
|
|
rs.revision.Set("")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-11 23:24:09 -06:00
|
|
|
newc, _ := strconv.Atoi(rs.revision.Get())
|
2024-01-10 18:18:01 -06:00
|
|
|
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb) + "." + strconv.Itoa(newc)
|
|
|
|
if newc <= oldc {
|
|
|
|
log.Warn("new version bad", newver, "vs old version", lasttag)
|
|
|
|
rs.newversion.Set("bad")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.Warn("new version ok", newver, "vs old version", lasttag)
|
|
|
|
rs.newversion.Set(newver)
|
|
|
|
return true
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
2024-01-10 00:15:27 -06:00
|
|
|
|
2024-01-10 00:43:15 -06:00
|
|
|
func (rs *RepoStatus) incrementVersion() {
|
|
|
|
lasttag := rs.lasttag.Get()
|
|
|
|
var major, minor, revision string
|
|
|
|
major, minor, revision = splitVersion(lasttag)
|
|
|
|
log.Warn("Should release version here", lasttag)
|
|
|
|
log.Warn("Should release a,b,c", major, minor, revision)
|
2024-01-10 00:15:27 -06:00
|
|
|
|
2024-01-10 18:18:01 -06:00
|
|
|
a, _ := strconv.Atoi(major)
|
|
|
|
b, _ := strconv.Atoi(minor)
|
|
|
|
c, _ := strconv.Atoi(revision)
|
2024-01-10 00:15:27 -06:00
|
|
|
|
2024-01-10 18:18:01 -06:00
|
|
|
rs.major.Add(a)
|
|
|
|
rs.major.Add(a + 1)
|
|
|
|
rs.major.Set(a)
|
2024-01-10 00:15:27 -06:00
|
|
|
|
2024-01-10 18:18:01 -06:00
|
|
|
rs.minor.Add(b)
|
|
|
|
rs.minor.Add(b + 1)
|
|
|
|
rs.minor.Set(b)
|
2024-01-10 00:15:27 -06:00
|
|
|
|
2024-01-10 00:43:15 -06:00
|
|
|
// rs.c := strconv.Atoi(revision)
|
2024-01-10 18:18:01 -06:00
|
|
|
rs.revision.Add(c + 1)
|
|
|
|
rs.revision.Add(c + 2)
|
|
|
|
rs.revision.Set(c + 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) recommend() {
|
|
|
|
log.Warn("Is repo dirty?", rs.dirtyLabel.Get())
|
|
|
|
log.Warn("list the known tags")
|
|
|
|
rs.DisableEverything()
|
|
|
|
rs.populateTags()
|
2024-01-13 20:30:33 -06:00
|
|
|
log.Warn("Does devel == jcarr?", rs.develBranchVersion.Get(), rs.jcarrBranchVersion.Get())
|
|
|
|
if rs.develBranchVersion.Get() != rs.jcarrBranchVersion.Get() {
|
2024-01-10 18:18:01 -06:00
|
|
|
log.Warn("devel does not equal jcarr")
|
|
|
|
log.Warn("merge or squash?")
|
2024-01-13 22:08:49 -06:00
|
|
|
rs.EnableMergeDevel()
|
|
|
|
rs.setMergeUserCommands()
|
|
|
|
label := "merge " + rs.GetUserName() + " into " + rs.GetDevelName()
|
|
|
|
rs.develMerge.SetText(label)
|
2024-01-10 18:18:01 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-13 20:30:33 -06:00
|
|
|
log.Warn("Does master == devel? ", rs.masterBranchVersion.Get(), rs.develBranchVersion.Get())
|
|
|
|
if rs.masterBranchVersion.Get() != rs.develBranchVersion.Get() {
|
2024-01-10 18:18:01 -06:00
|
|
|
log.Warn("master does not equal devel. merge devel into master")
|
|
|
|
rs.EnableMergeDevel()
|
2024-01-11 15:56:50 -06:00
|
|
|
rs.setMergeDevelCommands()
|
2024-01-13 22:08:49 -06:00
|
|
|
label := "merge " + rs.GetDevelName() + " into " + rs.GetMasterName()
|
|
|
|
rs.develMerge.SetText(label)
|
2024-01-10 18:18:01 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
rs.getLastTagVersion()
|
2024-01-13 20:30:33 -06:00
|
|
|
if rs.lasttag.Get() != rs.masterBranchVersion.Get() {
|
2024-01-10 18:18:01 -06:00
|
|
|
log.Warn("master does not equal last tag")
|
|
|
|
rs.incrementVersion()
|
|
|
|
rs.EnableSelectTag()
|
|
|
|
rs.setTag()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Warn("Is repo pushed upstream? git.wit.org or github?")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) generateCmd() bool {
|
|
|
|
// the length of 24 is arbitrary, but should be short
|
|
|
|
// they should be things like perhaps, major release names
|
|
|
|
// or something the users might see.
|
|
|
|
// aka: "Topsy", "Picasso", "Buzz", etc
|
|
|
|
|
|
|
|
if ! rs.setTag() {
|
|
|
|
log.Warn("tag sucked. fix your tag version")
|
|
|
|
rs.versionMessage.SetLabel("tag message (bad version)")
|
|
|
|
rs.releaseVersion.Disable()
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Warn("tag is valid!!!!")
|
|
|
|
rs.setGitCommands()
|
|
|
|
|
|
|
|
if rs.versionMessage.Get() == "" {
|
|
|
|
log.Warn("tag message is empty!!!!")
|
|
|
|
rs.releaseVersion.Disable()
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if len(rs.versionMessage.Get()) > 24 {
|
|
|
|
rs.versionMessage.SetLabel("tag message (too long)")
|
|
|
|
} else {
|
|
|
|
rs.versionMessage.SetLabel("tag message")
|
|
|
|
}
|
|
|
|
rs.releaseVersion.Enable()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-11 15:56:50 -06:00
|
|
|
func (rs *RepoStatus) runGitCommands() bool {
|
|
|
|
for _, line := range rs.versionCmds {
|
|
|
|
s := strings.Join(line, " ")
|
|
|
|
log.Warn("NEED TO RUN:", s)
|
|
|
|
err, b, output := runCmd(rs.repopath, line)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("ABEND EXECUTION")
|
|
|
|
log.Warn("error =", err)
|
|
|
|
log.Warn("output =", output)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.Warn("Returned with b =", b)
|
|
|
|
log.Warn("output was =", output)
|
|
|
|
log.Warn("RUN DONE")
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-10 18:18:01 -06:00
|
|
|
func (rs *RepoStatus) setGitCommands() {
|
|
|
|
var line1, line2, line3 []string
|
|
|
|
var all [][]string
|
|
|
|
|
|
|
|
newTag := rs.newversion.GetText()
|
|
|
|
line1 = append(line1, "git", "tag", "v" + newTag, "-m", rs.versionMessage.Get())
|
|
|
|
all = append(all, line1)
|
|
|
|
line2 = append(line2, "git", "push", "--tags")
|
|
|
|
all = append(all, line2)
|
|
|
|
line3 = append(line3, "git", "push", "--prune", "--tags")
|
|
|
|
all = append(all, line3)
|
|
|
|
|
|
|
|
rs.versionCmds = all
|
|
|
|
|
|
|
|
var tmp []string
|
|
|
|
// convert to displayable to the user text
|
|
|
|
for _, line := range all {
|
|
|
|
s := strings.Join(line, " ")
|
|
|
|
log.Warn("s =", s)
|
|
|
|
tmp = append(tmp, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
rs.versionCmdOutput.Set(strings.Join(tmp, "\n"))
|
|
|
|
}
|
2024-01-11 15:56:50 -06:00
|
|
|
|
|
|
|
func (rs *RepoStatus) setMergeDevelCommands() {
|
2024-01-13 22:08:49 -06:00
|
|
|
var line1, line2, line3 []string
|
2024-01-11 15:56:50 -06:00
|
|
|
var all [][]string
|
|
|
|
|
2024-01-13 22:08:49 -06:00
|
|
|
master := rs.GetMasterName()
|
|
|
|
devel := rs.GetDevelName()
|
|
|
|
|
|
|
|
line1 = append(line1, "git", "checkout", master)
|
2024-01-11 15:56:50 -06:00
|
|
|
all = append(all, line1)
|
2024-01-13 22:08:49 -06:00
|
|
|
line2 = append(line2, "git", "merge", devel)
|
2024-01-11 15:56:50 -06:00
|
|
|
all = append(all, line2)
|
2024-01-13 22:08:49 -06:00
|
|
|
line3 = append(line3, "git", "push")
|
|
|
|
all = append(all, line3)
|
|
|
|
|
|
|
|
rs.versionCmds = all
|
|
|
|
|
|
|
|
var tmp []string
|
|
|
|
// convert to displayable to the user text
|
|
|
|
for _, line := range all {
|
|
|
|
s := strings.Join(line, " ")
|
|
|
|
log.Warn("s =", s)
|
|
|
|
tmp = append(tmp, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
rs.versionCmdOutput.Set(strings.Join(tmp, "\n"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) setMergeUserCommands() {
|
|
|
|
var line1, line2, line3 []string
|
|
|
|
var all [][]string
|
|
|
|
|
|
|
|
devel := rs.GetDevelName()
|
|
|
|
user := rs.GetUserName()
|
|
|
|
|
|
|
|
line1 = append(line1, "git", "checkout", devel)
|
|
|
|
all = append(all, line1)
|
|
|
|
line2 = append(line2, "git", "merge", user)
|
|
|
|
all = append(all, line2)
|
|
|
|
line3 = append(line3, "git", "push")
|
|
|
|
all = append(all, line3)
|
2024-01-11 15:56:50 -06:00
|
|
|
|
|
|
|
rs.versionCmds = all
|
|
|
|
|
|
|
|
var tmp []string
|
|
|
|
// convert to displayable to the user text
|
|
|
|
for _, line := range all {
|
2024-01-10 18:18:01 -06:00
|
|
|
s := strings.Join(line, " ")
|
2024-01-11 15:56:50 -06:00
|
|
|
log.Warn("s =", s)
|
|
|
|
tmp = append(tmp, s)
|
2024-01-10 18:18:01 -06:00
|
|
|
}
|
2024-01-11 15:56:50 -06:00
|
|
|
|
|
|
|
rs.versionCmdOutput.Set(strings.Join(tmp, "\n"))
|
2024-01-10 00:15:27 -06:00
|
|
|
}
|