2024-01-09 15:34:53 -06:00
|
|
|
package repostatus
|
|
|
|
|
2024-01-18 00:57:43 -06:00
|
|
|
import (
|
2024-03-07 19:31:52 -06:00
|
|
|
"os"
|
2024-02-12 18:16:03 -06:00
|
|
|
"strings"
|
2024-03-02 17:52:45 -06:00
|
|
|
"unicode"
|
2024-02-12 18:16:03 -06:00
|
|
|
|
2024-01-09 15:34:53 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-18 00:57:43 -06:00
|
|
|
// "go.wit.com/gui/gui"
|
2024-01-09 15:34:53 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// reports externally if something has changed
|
|
|
|
// since the last time it was asked about it
|
2024-02-16 17:55:13 -06:00
|
|
|
func (rs *RepoStatus) Changed() (string, bool) {
|
2024-01-18 00:57:43 -06:00
|
|
|
if !rs.Ready() {
|
2024-02-16 17:55:13 -06:00
|
|
|
return "", false
|
2024-01-18 00:57:43 -06:00
|
|
|
}
|
2024-01-19 18:25:37 -06:00
|
|
|
|
2024-02-18 15:09:48 -06:00
|
|
|
return rs.getChanges(), rs.changed
|
2024-02-16 17:55:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// keeps a human readable list of things that have
|
2024-02-18 15:09:48 -06:00
|
|
|
// changed. todo: timestampe these?
|
|
|
|
func (rs *RepoStatus) getChanges() string {
|
2024-02-16 17:55:13 -06:00
|
|
|
return rs.changes
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) NoteChange(s string) {
|
2024-02-24 11:56:02 -06:00
|
|
|
log.Log(REPOWARN, "NoteChange() got", rs.String(), s)
|
2024-02-16 17:55:13 -06:00
|
|
|
rs.changed = true
|
|
|
|
rs.changes += s + "\n"
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
|
2024-02-15 22:50:50 -06:00
|
|
|
// deprecate this. returns the gopath right now
|
|
|
|
func (rs *RepoStatus) String() string {
|
2024-02-16 01:22:37 -06:00
|
|
|
// log.Warn("RepoStatus.String() is to be deprecated")
|
2024-02-15 22:50:50 -06:00
|
|
|
return rs.path.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns the go path for the repo. "go.wit.com/apps/autotypist"
|
|
|
|
func (rs *RepoStatus) GoName() string {
|
2024-02-17 15:49:12 -06:00
|
|
|
return rs.GoPath()
|
|
|
|
}
|
|
|
|
|
|
|
|
// not sure which name is easier to remember. probably this one
|
|
|
|
func (rs *RepoStatus) GoPath() string {
|
2024-02-19 14:42:59 -06:00
|
|
|
return rs.goPath.String()
|
2024-02-15 22:50:50 -06:00
|
|
|
}
|
|
|
|
|
2024-03-01 21:45:06 -06:00
|
|
|
// full path
|
|
|
|
func (rs *RepoStatus) FullPath() string {
|
|
|
|
return rs.realPath.String()
|
|
|
|
}
|
|
|
|
|
2024-02-20 06:54:11 -06:00
|
|
|
func (rs *RepoStatus) IsPrimitive() bool {
|
|
|
|
if rs.primitive.String() == "true" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-11-05 05:58:54 -06:00
|
|
|
func (rs *RepoStatus) IsProtobuf() (bool, []string, error) {
|
|
|
|
log.Info("are there .proto files in:", rs.Path())
|
|
|
|
all, err := ScanForProtobuf(rs.Path())
|
|
|
|
for i, s := range all {
|
|
|
|
log.Info("found i, s:", i, s)
|
|
|
|
}
|
|
|
|
return false, all, err
|
|
|
|
}
|
|
|
|
|
2024-02-15 22:50:50 -06:00
|
|
|
// returns the filesystem path to the repo
|
|
|
|
func (rs *RepoStatus) Path() string {
|
|
|
|
return rs.realPath.String()
|
|
|
|
}
|
|
|
|
|
2024-01-10 18:18:01 -06:00
|
|
|
func (rs *RepoStatus) Show() {
|
2024-01-18 00:57:43 -06:00
|
|
|
if !rs.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-10 18:18:01 -06:00
|
|
|
log.Log(CHANGE, "Show() window ready =", rs.ready)
|
|
|
|
rs.window.Show()
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
|
2024-01-10 18:18:01 -06:00
|
|
|
func (rs *RepoStatus) Hide() {
|
2024-01-18 00:57:43 -06:00
|
|
|
if !rs.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-10 18:18:01 -06:00
|
|
|
log.Log(CHANGE, "Hide() window ready =", rs.ready)
|
|
|
|
rs.window.Hide()
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
|
2024-01-10 18:18:01 -06:00
|
|
|
func (rs *RepoStatus) Toggle() {
|
2024-01-18 00:57:43 -06:00
|
|
|
if !rs.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-10 18:18:01 -06:00
|
|
|
log.Log(CHANGE, "Toggle() window ready =", rs.ready)
|
2024-02-11 18:56:55 -06:00
|
|
|
if rs.window.Hidden() {
|
2024-01-10 18:18:01 -06:00
|
|
|
rs.Show()
|
2024-01-09 15:34:53 -06:00
|
|
|
} else {
|
2024-01-10 18:18:01 -06:00
|
|
|
rs.Hide()
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-10 18:18:01 -06:00
|
|
|
func (rs *RepoStatus) Ready() bool {
|
2024-01-18 00:57:43 -06:00
|
|
|
if rs == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if rs.window == nil {
|
|
|
|
return false
|
|
|
|
}
|
2024-01-10 18:18:01 -06:00
|
|
|
return rs.ready
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
|
2024-02-16 11:41:29 -06:00
|
|
|
func (rs *RepoStatus) IsGoLang() bool {
|
|
|
|
if !rs.Ready() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if rs.isGoLang.String() == "true" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-03-07 19:31:52 -06:00
|
|
|
// experiment to go package type
|
2024-02-12 18:16:03 -06:00
|
|
|
func (rs *RepoStatus) RepoType() string {
|
2024-02-16 11:41:29 -06:00
|
|
|
if !rs.IsGoLang() {
|
|
|
|
return ""
|
|
|
|
}
|
2024-03-07 19:31:52 -06:00
|
|
|
if !rs.Exists("go.mod") {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
os.Setenv("GO111MODULE", "off")
|
2024-02-12 18:16:03 -06:00
|
|
|
err, output := rs.RunCmd([]string{"go", "list", "-f", "'{{if eq .Name \"main\"}}binary{{else}}library{{end}}'"})
|
|
|
|
if err == nil {
|
|
|
|
output = strings.Trim(output, "'")
|
2024-02-16 01:22:37 -06:00
|
|
|
// log.Info("go package is:", output)
|
2024-02-12 18:16:03 -06:00
|
|
|
return output
|
|
|
|
}
|
2024-02-16 01:22:37 -06:00
|
|
|
// log.Info("package is: unknown", err)
|
2024-02-12 18:16:03 -06:00
|
|
|
return ""
|
|
|
|
}
|
2024-02-12 21:50:54 -06:00
|
|
|
|
|
|
|
func (rs *RepoStatus) BinaryName() string {
|
|
|
|
// get the package name from the repo name
|
|
|
|
path := rs.String()
|
|
|
|
parts := strings.Split(path, "/")
|
|
|
|
name := parts[len(parts)-1]
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) Build() bool {
|
2024-02-16 11:41:29 -06:00
|
|
|
if !rs.IsGoLang() {
|
|
|
|
return false
|
|
|
|
}
|
2024-02-12 21:50:54 -06:00
|
|
|
name := rs.BinaryName()
|
|
|
|
// removes the binary if it already exists
|
|
|
|
rs.RunCmd([]string{"rm", "-f", name})
|
|
|
|
if rs.Exists(name) {
|
|
|
|
log.Warn("file could not be removed filename =", name)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.Info("need to build here", rs.String())
|
2024-02-15 22:50:50 -06:00
|
|
|
// rs.RunCmd([]string{"go", "build", "-v", "-x"})
|
|
|
|
rs.XtermBash([]string{"go", "build", "-v", "-x"})
|
2024-02-12 21:50:54 -06:00
|
|
|
if rs.Exists(name) {
|
|
|
|
log.Warn("build worked", name)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
log.Warn("build failed", name)
|
|
|
|
return false
|
|
|
|
}
|
2024-02-18 15:09:48 -06:00
|
|
|
|
|
|
|
func (rs *RepoStatus) GetTargetVersion() string {
|
|
|
|
return rs.targetReleaseVersion.String()
|
|
|
|
}
|
|
|
|
|
2024-02-20 06:54:11 -06:00
|
|
|
func (rs *RepoStatus) GetCurrentVersion() string {
|
|
|
|
return rs.currentVersion.String()
|
|
|
|
}
|
|
|
|
|
2024-02-23 01:23:29 -06:00
|
|
|
func (rs *RepoStatus) LastTag() string {
|
|
|
|
return rs.lasttag.String()
|
|
|
|
}
|
|
|
|
|
2024-02-18 15:09:48 -06:00
|
|
|
func (rs *RepoStatus) IncrementVersion() bool {
|
2024-02-23 00:10:30 -06:00
|
|
|
rs.incrementRevision()
|
|
|
|
rs.EnableSelectTag()
|
|
|
|
rs.setTag()
|
|
|
|
newtag := "v" + rs.newversion.String()
|
2024-02-23 01:23:29 -06:00
|
|
|
log.Log(REPOWARN, rs.GoPath(), "old version:", rs.LastTag(), "new version:", newtag)
|
2024-02-23 00:10:30 -06:00
|
|
|
rs.targetReleaseVersion.SetText(newtag)
|
|
|
|
return true
|
2024-02-18 15:09:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: run this through the sanity check!
|
|
|
|
func (rs *RepoStatus) SetTargetVersion(s string) {
|
|
|
|
// todo: redo setTag to do increment logic
|
|
|
|
// func (rs *RepoStatus) setTag() bool {
|
|
|
|
rs.targetReleaseVersion.SetText(s)
|
|
|
|
}
|
2024-02-19 14:42:59 -06:00
|
|
|
|
2024-02-23 11:00:33 -06:00
|
|
|
func (rs *RepoStatus) IsPrivate() bool {
|
|
|
|
if rs.private.String() == "true" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2024-02-19 16:29:10 -06:00
|
|
|
}
|
|
|
|
|
2024-02-23 11:00:33 -06:00
|
|
|
func (rs *RepoStatus) SetPrivate(b bool) {
|
|
|
|
if b {
|
|
|
|
rs.private.SetText("true")
|
|
|
|
} else {
|
|
|
|
rs.private.SetText("false")
|
|
|
|
}
|
2024-02-19 16:29:10 -06:00
|
|
|
}
|
2024-02-24 11:56:02 -06:00
|
|
|
|
|
|
|
// returns a name for human consuption only
|
|
|
|
// todo: implement nicknames
|
|
|
|
func (rs *RepoStatus) Name() string {
|
|
|
|
if rs.IsGoLang() {
|
|
|
|
return rs.GoPath()
|
|
|
|
}
|
|
|
|
return rs.Path()
|
|
|
|
}
|
2024-03-02 17:52:45 -06:00
|
|
|
|
|
|
|
func trimNonNumericFromStart(s string) string {
|
|
|
|
for i, r := range s {
|
|
|
|
if unicode.IsDigit(r) {
|
|
|
|
return s[i:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) DebianReleaseVersion() string {
|
|
|
|
lasttag := rs.GetLastTagVersion()
|
|
|
|
newv := trimNonNumericFromStart(lasttag)
|
|
|
|
if newv == "" {
|
|
|
|
newv = "0.0"
|
|
|
|
if lasttag != "" {
|
|
|
|
newv += "-" + lasttag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newv
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *RepoStatus) DebianCurrentVersion() string {
|
|
|
|
cbversion := rs.GetCurrentBranchVersion()
|
|
|
|
|
|
|
|
newv := trimNonNumericFromStart(cbversion)
|
|
|
|
if newv == "" {
|
|
|
|
newv = "0.0"
|
|
|
|
}
|
|
|
|
if rs.CheckDirty() {
|
|
|
|
newv += "-dirty"
|
|
|
|
}
|
|
|
|
return newv
|
|
|
|
}
|