2024-01-09 15:34:53 -06:00
|
|
|
package repostatus
|
|
|
|
|
|
|
|
import (
|
2024-01-18 00:57:43 -06:00
|
|
|
"errors"
|
2024-01-09 15:34:53 -06:00
|
|
|
"fmt"
|
2024-02-16 11:41:29 -06:00
|
|
|
"strings"
|
2024-01-09 15:34:53 -06:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
2024-02-16 11:41:29 -06:00
|
|
|
func (rs *RepoStatus) gitBranchAll() {
|
|
|
|
err, out := rs.RunCmd([]string{"git", "branch", "--all"})
|
|
|
|
if err != nil {
|
|
|
|
log.Log(WARN, "git branch failed", rs.String())
|
|
|
|
}
|
|
|
|
all := strings.Split(out, "\n")
|
|
|
|
for _, s := range all {
|
|
|
|
// log.Log(WARN, "found branch", i, s)
|
|
|
|
rs.targetBranch.AddText(s)
|
|
|
|
}
|
|
|
|
// i := len(all)
|
|
|
|
// log.Log(WARN, "branch count =", i)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) UpdateNew() {
|
|
|
|
if !rs.Ready() {
|
|
|
|
log.Log(WARN, "can't update yet. ready is false")
|
|
|
|
log.Error(errors.New("Update() is not ready yet"))
|
|
|
|
return
|
|
|
|
}
|
2024-02-16 17:55:13 -06:00
|
|
|
|
|
|
|
// store the current checked out branch name and version
|
|
|
|
rs.checkCurrentBranchName()
|
|
|
|
rs.checkCurrentBranchVersion()
|
|
|
|
|
|
|
|
// read in the tags
|
2024-02-16 11:41:29 -06:00
|
|
|
rs.populateTags()
|
2024-02-16 17:55:13 -06:00
|
|
|
|
|
|
|
// record if the repo is dirty
|
2024-02-16 11:41:29 -06:00
|
|
|
rs.CheckDirty()
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
// store the last tag version
|
|
|
|
rs.setLastTagVersion()
|
|
|
|
|
|
|
|
// store the master branch version
|
2024-02-16 11:41:29 -06:00
|
|
|
mName := rs.GetMasterBranchName()
|
2024-02-16 17:55:13 -06:00
|
|
|
out, _ := rs.gitDescribeByName(mName)
|
|
|
|
rs.setMasterVersion(out)
|
2024-02-16 11:41:29 -06:00
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
// store the devel branch version
|
2024-02-16 11:41:29 -06:00
|
|
|
dName := rs.GetDevelBranchName()
|
2024-02-16 17:55:13 -06:00
|
|
|
if dName == "" {
|
|
|
|
rs.setDevelVersion("")
|
2024-02-16 11:41:29 -06:00
|
|
|
} else {
|
2024-02-16 17:55:13 -06:00
|
|
|
out, _ = rs.gitDescribeByName(dName)
|
|
|
|
rs.setDevelVersion(out)
|
2024-02-16 11:41:29 -06:00
|
|
|
}
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
// store the user branch version
|
2024-02-16 11:41:29 -06:00
|
|
|
uName := rs.GetUserBranchName()
|
2024-02-16 17:55:13 -06:00
|
|
|
if uName == "" {
|
|
|
|
rs.setUserVersion("")
|
2024-02-16 11:41:29 -06:00
|
|
|
} else {
|
2024-02-16 17:55:13 -06:00
|
|
|
out, _ = rs.gitDescribeByName(uName)
|
|
|
|
rs.setUserVersion(out)
|
2024-02-16 11:41:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-16 17:55:13 -06:00
|
|
|
/*
|
2024-02-16 11:41:29 -06:00
|
|
|
// deprecate / redo what is left of this
|
|
|
|
func (rs *RepoStatus) UpdateOld() {
|
2024-01-18 00:57:43 -06:00
|
|
|
if !rs.Ready() {
|
2024-01-09 15:34:53 -06:00
|
|
|
log.Log(WARN, "can't update yet. ready is false")
|
|
|
|
log.Error(errors.New("Update() is not ready yet"))
|
|
|
|
return
|
|
|
|
}
|
2024-01-23 10:52:17 -06:00
|
|
|
log.Log(INFO, "Update() START")
|
2024-01-18 00:57:43 -06:00
|
|
|
duration := timeFunction(func() {
|
2024-02-16 11:41:29 -06:00
|
|
|
rs.UpdateNew()
|
2024-01-09 15:34:53 -06:00
|
|
|
|
2024-01-17 03:59:13 -06:00
|
|
|
if rs.dirtyLabel.String() != "no" {
|
|
|
|
log.Warn("dirty label != no. actual value:", rs.dirtyLabel.String())
|
2024-01-10 19:44:10 -06:00
|
|
|
rs.DisableEverything()
|
2024-01-18 17:37:50 -06:00
|
|
|
rs.CheckBranches()
|
2024-01-10 19:44:10 -06:00
|
|
|
return
|
2024-01-10 18:18:01 -06:00
|
|
|
}
|
2024-01-10 19:44:10 -06:00
|
|
|
|
2024-01-25 01:30:01 -06:00
|
|
|
master := rs.mainWorkingName.String()
|
|
|
|
devel := rs.develWorkingName.String()
|
|
|
|
user := rs.userWorkingName.String()
|
2024-01-11 15:56:50 -06:00
|
|
|
|
2024-01-13 20:30:33 -06:00
|
|
|
// rs.CheckDirty() this runs
|
2024-01-23 10:52:17 -06:00
|
|
|
log.Log(INFO, "checkoutBranch", master)
|
2024-01-11 15:56:50 -06:00
|
|
|
rs.checkoutBranch("master", master)
|
2024-01-23 10:52:17 -06:00
|
|
|
log.Log(INFO, "checkoutBranch", devel)
|
2024-01-11 15:56:50 -06:00
|
|
|
rs.checkoutBranch("devel", devel)
|
2024-01-23 10:52:17 -06:00
|
|
|
log.Log(INFO, "checkoutBranch", user)
|
2024-01-11 15:56:50 -06:00
|
|
|
rs.checkoutBranch("user", user)
|
2024-01-10 19:44:10 -06:00
|
|
|
|
|
|
|
rs.recommend()
|
2024-01-18 17:37:50 -06:00
|
|
|
rs.CheckBranches()
|
2024-01-30 13:31:46 -06:00
|
|
|
|
|
|
|
label := "merge " + rs.userWorkingName.String() + " to " + rs.develWorkingName.String()
|
|
|
|
rs.develMergeB.SetLabel(label)
|
|
|
|
|
|
|
|
label = "merge " + rs.develWorkingName.String() + " to " + rs.mainWorkingName.String()
|
|
|
|
rs.mainMergeB.SetLabel(label)
|
2024-01-09 15:34:53 -06:00
|
|
|
})
|
|
|
|
rs.setSpeed(duration)
|
2024-01-23 10:52:17 -06:00
|
|
|
log.Log(INFO, "Update() END")
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
2024-02-16 17:55:13 -06:00
|
|
|
*/
|
2024-01-09 15:34:53 -06:00
|
|
|
|
|
|
|
func (rs *RepoStatus) setSpeed(duration time.Duration) {
|
|
|
|
s := fmt.Sprint(duration)
|
|
|
|
if rs.speedActual == nil {
|
2024-01-23 10:52:17 -06:00
|
|
|
log.Log(WARN, "rs.speedActual == nil")
|
2024-01-09 15:34:53 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.speedActual.SetValue(s)
|
2024-01-09 15:34:53 -06:00
|
|
|
|
2024-01-18 00:57:43 -06:00
|
|
|
if duration > 500*time.Millisecond {
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.speed.SetValue("SLOW")
|
2024-01-18 00:57:43 -06:00
|
|
|
} else if duration > 100*time.Millisecond {
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.speed.SetValue("OK")
|
2024-01-09 15:34:53 -06:00
|
|
|
} else {
|
2024-01-19 12:36:52 -06:00
|
|
|
rs.speed.SetValue("FAST")
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-10 18:18:01 -06:00
|
|
|
|
|
|
|
// disable all things besides Update() button
|
|
|
|
func (rs *RepoStatus) DisableEverything() {
|
2024-01-23 10:52:17 -06:00
|
|
|
log.Log(INFO, "DisableEverything()")
|
2024-01-10 18:18:01 -06:00
|
|
|
|
|
|
|
// choosing a major, minor or revision
|
|
|
|
rs.major.Disable()
|
|
|
|
rs.minor.Disable()
|
|
|
|
rs.revision.Disable()
|
|
|
|
|
|
|
|
// disable adding a tag message
|
|
|
|
rs.versionMessage.Disable()
|
|
|
|
|
|
|
|
// disable the merge devel to master button
|
2024-01-30 13:31:46 -06:00
|
|
|
rs.develMergeB.Disable()
|
2024-01-10 18:18:01 -06:00
|
|
|
|
|
|
|
// disable the tag a new version button
|
|
|
|
rs.releaseVersion.Disable()
|
|
|
|
}
|
|
|
|
|
|
|
|
// this means devel needs to be merged to master
|
|
|
|
func (rs *RepoStatus) EnableMergeDevel() {
|
|
|
|
rs.DisableEverything()
|
|
|
|
|
2024-01-30 13:31:46 -06:00
|
|
|
rs.develMergeB.Enable()
|
2024-01-10 18:18:01 -06:00
|
|
|
}
|
|
|
|
|
2024-01-19 18:25:37 -06:00
|
|
|
func (rs *RepoStatus) Disable() {
|
|
|
|
rs.window.Disable()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) Enable() {
|
|
|
|
rs.window.Enable()
|
|
|
|
}
|
|
|
|
|
2024-01-10 18:18:01 -06:00
|
|
|
// this means you need to release a new version of the master repository
|
|
|
|
func (rs *RepoStatus) EnableSelectTag() {
|
|
|
|
rs.DisableEverything()
|
|
|
|
|
|
|
|
// choosing a major, minor or revision
|
|
|
|
rs.major.Enable()
|
|
|
|
rs.minor.Enable()
|
|
|
|
rs.revision.Enable()
|
|
|
|
|
|
|
|
// disable adding a tag message
|
|
|
|
rs.versionMessage.Enable()
|
2024-01-20 21:18:03 -06:00
|
|
|
|
2024-01-30 13:31:46 -06:00
|
|
|
rs.develMergeB.SetLabel("ready to release")
|
2024-01-10 18:18:01 -06:00
|
|
|
|
2024-01-25 22:59:49 -06:00
|
|
|
if len(rs.versionMessage.String()) == 0 {
|
|
|
|
// force there to be a commit message
|
|
|
|
rs.releaseVersion.Disable()
|
|
|
|
} else {
|
|
|
|
rs.generateCmd()
|
|
|
|
rs.releaseVersion.Enable()
|
|
|
|
}
|
2024-01-10 18:18:01 -06:00
|
|
|
}
|