diff options
| author | Jeff Carr <[email protected]> | 2024-01-23 10:52:17 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-23 10:52:17 -0600 |
| commit | 294119e7c2678b609aa8b66b6ffc219f1c399309 (patch) | |
| tree | 1a0b9e7de365e6540d0b3f9cc762a852472e32f6 /draw.go | |
| parent | 7546209d24055bb1252ba3cab63e09f692c3e74b (diff) | |
buttons for scanning .git/config and go.sum
common branch handling
scan go.sum & .git/config on New()
parse go & git config files
cleaner debugging
cleaning up logging
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'draw.go')
| -rw-r--r-- | draw.go | 161 |
1 files changed, 125 insertions, 36 deletions
@@ -1,6 +1,7 @@ package repostatus import ( + "path/filepath" "strconv" "strings" @@ -37,10 +38,20 @@ func (rs *RepoStatus) drawGitBranches() { rs.masterDrop = gadgets.NewBasicDropdown(newgrid, "main branch") rs.develDrop = gadgets.NewBasicDropdown(newgrid, "devel branch") rs.userDrop = gadgets.NewBasicDropdown(newgrid, "user branch") + + rs.lasttag = gadgets.NewOneLiner(newgrid, "last tag") + + rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master") + rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel") + rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user") + + rs.currentBranch = gadgets.NewOneLiner(newgrid, "current branch") + rs.currentVersion = gadgets.NewOneLiner(newgrid, "current version") + var master = "" all := rs.getBranches() for _, branch := range all { - log.Warn("getBranches()", branch) + log.Log(INFO, "getBranches()", branch) rs.masterDrop.AddText(branch) rs.develDrop.AddText(branch) rs.userDrop.AddText(branch) @@ -51,6 +62,7 @@ func (rs *RepoStatus) drawGitBranches() { master = "main" } } + // relabel the various gadgets with the right branch name rs.masterBranchVersion.SetLabel(master) @@ -65,13 +77,84 @@ func (rs *RepoStatus) drawGitBranches() { rs.checkBranchesButton = newgrid.NewButton("check branches", func() { if rs.CheckBranches() { - log.Warn("Branches are perfect") + log.Log(INFO, "Branches are perfect") } else { - log.Warn("Branches are not perfect") + log.Log(INFO, "Branches are not perfect") + } + }) + newgrid.NewButton("parse git and go config", func() { + ScanGoSrc() + }) + + newgrid.NewButton("show .git/config", func() { + if rs.gitConfig == nil { + log.Log(WARN, "Nonexistant or damaged .git/config", rs.GetPath()) + return + } + log.Log(WARN, ".git/config:", rs.realPath.String()) + + // The info: + for name, remote := range rs.gitConfig.remotes { + log.Log(WARN, " ", name, remote.url) + } + for name, branch := range rs.gitConfig.branches { + log.Log(WARN, " ", name, "remote:", branch.remote, "merge", branch.merge) + } + }) + newgrid.NewButton("check go.sum", func() { + if rs.ReadGoMod() { + log.Log(INFO, "parsed go.mod", rs.realPath.String()) + } else { + log.Log(WARN, "Something went wrong parsing go.mod", rs.realPath.String()) + } + + log.Log(WARN, "go.sum:", rs.realPath.String()) + for depname, version := range rs.goConfig { + log.Log(WARN, " ", depname, version) } + }) } +/* +func (rs *RepoStatus) ScanConfig(path string) { + log.Log(WARN, "repo =", path) + filename := filepath.Join(path, ".git/config") + + rs.gitConfig, err := ReadGitConfig(filename) + if err != nil { + log.Log(WARN, "Error reading .git/config:", err) + continue + } + + rs.goConfig, err := ReadGoMod(path) +} +*/ + +func ScanGoSrc() { + for i, path := range listGitDirectories() { + log.Log(WARN, "repo =", i, path) + filename := filepath.Join(path, ".git/config") + gitConfig, err := readGitConfig(filename) + if err != nil { + log.Log(WARN, "Error reading .git/config:", err) + continue + } + + // Example of printing the parsed config + for section, options := range gitConfig.branches { + log.Log(WARN, "\t", section, options) + } + /* + _, err = ReadGoMod(path) // map[string]string { + if err != nil { + log.Log(WARN, "\tgo.sum scan failed") + } + */ + + } +} + func (rs *RepoStatus) drawGitStatus() { rs.gitStatusGroup = rs.window.Box().NewGroup("What GO Knows It Has") newgrid := rs.gitStatusGroup.NewGrid("gridnuts", 2, 2) @@ -79,23 +162,29 @@ func (rs *RepoStatus) drawGitStatus() { 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") + rs.goSrcPath = gadgets.NewOneLiner(newgrid, "go/src") + rs.realPath = gadgets.NewOneLiner(newgrid, "fullpath") + rs.realPath.Hide() + rs.mainWorkingName = gadgets.NewOneLiner(newgrid, "main working branch") + rs.mainWorkingName.SetValue("???") + rs.develWorkingName = gadgets.NewOneLiner(newgrid, "devel working branch") + rs.develWorkingName.SetValue("devel") + rs.userWorkingName = gadgets.NewOneLiner(newgrid, "user working branch") + rs.userWorkingName.SetValue("uid") + rs.tagsDrop = gadgets.NewBasicDropdown(newgrid, "all releases") // git for-each-ref --sort=taggerdate --format '%(tag) ,,,_,,, %(subject)' refs/tags var cmd []string cmd = append(cmd, "git", "for-each-ref", "--sort=taggerdate", "--format", "%(tag) %(subject)", "refs/tags") _, _, output := RunCmd("/home/jcarr/go/src/"+rs.repopath, cmd) - log.Info(output) + log.Log(INFO, output) for _, line := range strings.Split(output, "\n") { rs.tagsDrop.AddText(line) } - rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master") - rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel") - rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user") +// rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master") +// rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel") +// rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user") rs.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty") @@ -187,8 +276,8 @@ func (rs *RepoStatus) setTag() bool { oldb, _ := strconv.Atoi(minor) oldc, _ := strconv.Atoi(revision) - log.Warn("current version here", lasttag) - log.Warn("current release a,b,c =", major, minor, revision) + log.Log(INFO, "current version here", lasttag) + log.Log(INFO, "current release a,b,c =", major, minor, revision) newa, _ := strconv.Atoi(rs.major.String()) @@ -199,7 +288,7 @@ func (rs *RepoStatus) setTag() bool { return false } if newa > olda { - log.Warn("new version ok", newver, "vs old version", lasttag) + log.Log(INFO, "new version ok", newver, "vs old version", lasttag) rs.newversion.SetLabel(newver) rs.minor.SetText("") rs.revision.SetText("") @@ -215,7 +304,7 @@ func (rs *RepoStatus) setTag() bool { } if newb > oldb { - log.Warn("new version ok", newver, "vs old version", lasttag) + log.Log(INFO, "new version ok", newver, "vs old version", lasttag) rs.newversion.SetLabel(newver) rs.revision.SetText("") return true @@ -228,7 +317,7 @@ func (rs *RepoStatus) setTag() bool { rs.newversion.SetLabel("bad") return false } - log.Warn("new version ok", newver, "vs old version", lasttag) + log.Log(INFO, "new version ok", newver, "vs old version", lasttag) rs.newversion.SetLabel(newver) return true } @@ -238,7 +327,7 @@ func (rs *RepoStatus) incrementVersion() { 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) + log.Log(INFO, "Should release a,b,c", major, minor, revision) a, _ := strconv.Atoi(major) b, _ := strconv.Atoi(minor) @@ -259,23 +348,23 @@ func (rs *RepoStatus) incrementVersion() { } func (rs *RepoStatus) recommend() { - log.Warn("Is repo dirty?", rs.dirtyLabel.String()) - log.Warn("list the known tags") + log.Log(INFO, "Is repo dirty?", rs.dirtyLabel.String()) + log.Log(INFO, "list the known tags") rs.DisableEverything() rs.populateTags() - log.Warn("Does devel == user?", rs.develBranchVersion.String(), rs.userBranchVersion.String()) + log.Log(INFO, "Does devel == user?", rs.develBranchVersion.String(), rs.userBranchVersion.String()) if rs.develBranchVersion.String() != rs.userBranchVersion.String() { - log.Warn("devel does not equal user") - log.Warn("merge or squash?") + log.Log(INFO, "devel does not equal user") + log.Log(INFO, "merge or squash?") rs.EnableMergeDevel() rs.setMergeUserCommands() label := "merge user into " + rs.GetDevelBranchName() rs.develMerge.SetLabel(label) return } - log.Warn("Does master == devel? ", rs.masterBranchVersion.String(), rs.develBranchVersion.String()) + log.Log(INFO, "Does master == devel? ", rs.masterBranchVersion.String(), rs.develBranchVersion.String()) if rs.masterBranchVersion.String() != rs.develBranchVersion.String() { - log.Warn("master does not equal devel. merge devel into master") + log.Log(INFO, "master does not equal devel. merge devel into master") rs.EnableMergeDevel() rs.setMergeDevelCommands() label := "merge devel into " + rs.GetMasterBranchName() @@ -284,13 +373,13 @@ func (rs *RepoStatus) recommend() { } rs.getLastTagVersion() if rs.lasttag.String() != rs.masterBranchVersion.String() { - log.Warn("master does not equal last tag") + log.Log(INFO, "master does not equal last tag") rs.incrementVersion() rs.EnableSelectTag() rs.setTag() return } - log.Warn("Is repo pushed upstream? git.wit.org or github?") + log.Log(INFO, "Is repo pushed upstream? git.wit.org or github?") } func (rs *RepoStatus) generateCmd() bool { @@ -300,17 +389,17 @@ func (rs *RepoStatus) generateCmd() bool { // aka: "Topsy", "Picasso", "Buzz", etc if !rs.setTag() { - log.Warn("tag sucked. fix your tag version") + log.Log(INFO, "tag sucked. fix your tag version") rs.versionMessage.SetLabel("tag message (bad version)") rs.releaseVersion.Disable() return false } - log.Warn("tag is valid!!!!") + log.Log(INFO, "tag is valid!!!!") rs.setGitCommands() if rs.versionMessage.String() == "" { - log.Warn("tag message is empty!!!!") + log.Log(INFO, "tag message is empty!!!!") rs.releaseVersion.Disable() return false } @@ -326,7 +415,7 @@ func (rs *RepoStatus) generateCmd() bool { func (rs *RepoStatus) runGitCommands() bool { for _, line := range rs.versionCmds { s := strings.Join(line, " ") - log.Warn("NEED TO RUN:", s) + log.Log(INFO, "NEED TO RUN:", s) rs.develMerge.SetText(s) err, b, output := runCmd(rs.repopath, line) if err != nil { @@ -335,9 +424,9 @@ func (rs *RepoStatus) runGitCommands() bool { log.Warn("output =", output) return false } - log.Warn("Returned with b =", b) - log.Warn("output was =", output) - log.Warn("RUN DONE") + log.Log(INFO, "Returned with b =", b) + log.Log(INFO, "output was =", output) + log.Log(INFO, "RUN DONE") } return true } @@ -360,7 +449,7 @@ func (rs *RepoStatus) setGitCommands() { // convert to displayable to the user text for _, line := range all { s := strings.Join(line, " ") - log.Warn("s =", s) + log.Log(INFO, "s =", s) tmp = append(tmp, s) } @@ -387,7 +476,7 @@ func (rs *RepoStatus) setMergeDevelCommands() { // convert to displayable to the user text for _, line := range all { s := strings.Join(line, " ") - log.Warn("s =", s) + log.Log(INFO, "s =", s) tmp = append(tmp, s) } @@ -414,7 +503,7 @@ func (rs *RepoStatus) setMergeUserCommands() { // convert to displayable to the user text for _, line := range all { s := strings.Join(line, " ") - log.Warn("s =", s) + log.Log(INFO, "s =", s) tmp = append(tmp, s) } |
