repolist/newRepo.go

209 lines
5.0 KiB
Go
Raw Normal View History

2024-02-22 19:28:23 -06:00
package repolist
import (
"strings"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/log"
)
2024-02-23 09:02:51 -06:00
func (r *RepoRow) Hidden() bool {
2024-02-22 21:12:35 -06:00
return r.hidden
}
2024-02-23 09:02:51 -06:00
func (r *RepoRow) Hide() {
2024-02-22 21:12:35 -06:00
r.pLabel.Hide()
r.lastTag.Hide()
r.currentName.Hide()
r.currentVersion.Hide()
r.masterVersion.Hide()
r.develVersion.Hide()
r.userVersion.Hide()
r.gitState.Hide()
r.endBox.Hide()
// r.statusButton.Hide()
// r.diffButton.Hide()
2024-02-29 21:57:33 -06:00
// r.goState.Hide()
2024-02-22 21:12:35 -06:00
r.targetV.Hide()
r.hidden = true
}
2024-02-23 09:02:51 -06:00
func (r *RepoRow) Show() {
2024-02-22 21:12:35 -06:00
r.pLabel.Show()
r.lastTag.Show()
r.currentName.Show()
r.currentVersion.Show()
r.masterVersion.Show()
r.develVersion.Show()
r.userVersion.Show()
r.gitState.Show()
r.endBox.Show()
// r.statusButton.Show()
// r.diffButton.Show()
2024-02-29 21:57:33 -06:00
// r.goState.Show()
2024-02-22 21:12:35 -06:00
r.targetV.Show()
r.hidden = false
}
2024-02-23 09:02:51 -06:00
func (r *RepoList) NewRepo(path string) (*RepoRow, error) {
2024-02-23 11:01:23 -06:00
test, ok := r.allrepos[path]
if ok {
// this repo already exists
return test, nil
}
2024-02-22 19:28:23 -06:00
status, err := repostatus.New(path)
if err != nil {
return nil, err
}
2024-02-23 09:02:51 -06:00
newRepo := new(RepoRow)
2024-02-22 19:28:23 -06:00
newRepo.Status = status
newRepo.pLabel = r.reposgrid.NewLabel(path).SetProgName("path")
newRepo.hidden = false
r.allrepos[path] = newRepo
newRepo.NewScan()
switch r.viewName {
case "autotypist":
r.makeAutotypistView(newRepo)
case "guireleaser":
r.makeGuireleaserView(newRepo)
default:
r.makeAutotypistView(newRepo)
}
r.reposgrid.NextRow()
return newRepo, nil
}
2024-02-23 09:02:51 -06:00
func (r *RepoList) makeAutotypistView(newRepo *RepoRow) {
2024-02-22 19:28:23 -06:00
grid := r.reposgrid
newRepo.lastTag = newRepo.Status.MirrorLastTag()
grid.Append(newRepo.lastTag)
newRepo.masterVersion = newRepo.Status.MirrorMasterVersion()
grid.Append(newRepo.masterVersion)
newRepo.develVersion = newRepo.Status.MirrorDevelVersion()
grid.Append(newRepo.develVersion)
newRepo.userVersion = newRepo.Status.MirrorUserVersion()
grid.Append(newRepo.userVersion)
newRepo.gitState = newRepo.Status.MirrorGitState()
grid.Append(newRepo.gitState)
newRepo.currentName = newRepo.Status.MirrorCurrentName()
grid.Append(newRepo.currentName)
newRepo.currentVersion = newRepo.Status.MirrorCurrentVersion()
grid.Append(newRepo.currentVersion)
newRepo.endBox = grid.NewHorizontalBox("HBOX")
newRepo.endBox.NewButton("Configure", func() {
newRepo.Status.Toggle()
})
newRepo.endBox.NewButton("show diff", func() {
r.reposbox.Disable()
log.Log(REPOWARN, "show diff currentName =", newRepo.currentName.String())
log.Log(REPOWARN, "show diff masterVersion =", newRepo.masterVersion.String())
// newRepo.Status.XtermNohup([]string{"git diff"})
newRepo.Status.Xterm("git diff; bash")
r.reposbox.Enable()
})
newRepo.endBox.NewButton("commit all", func() {
2024-02-25 13:10:23 -06:00
if !newRepo.Status.IsUserBranch() {
log.Log(REPOWARN, "can not commit on non user branch")
return
}
2024-02-22 19:28:23 -06:00
r.reposbox.Disable()
// restore anything staged so everything can be reviewed
newRepo.Status.RunCmd([]string{"git", "restore", "--staged", "."})
newRepo.Status.XtermWait("git diff")
newRepo.Status.XtermWait("git add --all")
newRepo.Status.XtermWait("git commit -a")
newRepo.Status.XtermWait("git push")
if newRepo.Status.CheckDirty() {
// commit was not done, restore diff
newRepo.Status.RunCmd([]string{"git", "restore", "--staged", "."})
} else {
newRepo.NewScan()
}
r.reposbox.Enable()
})
if strings.HasPrefix(newRepo.GoPath(), "go.wit.com/apps") {
var showBuildB bool = false
switch newRepo.Status.RepoType() {
case "binary":
log.Info("showing compile here button")
showBuildB = true
case "library":
// log.Info("library here. Hide()")
default:
// log.Info("unknown RepoType", newRepo.Status.RepoType())
}
if showBuildB {
newRepo.endBox.NewButton("build", func() {
newRepo.Status.Build()
})
}
}
}
2024-02-23 09:02:51 -06:00
func (r *RepoList) makeGuireleaserView(newRepo *RepoRow) {
2024-02-22 19:28:23 -06:00
grid := r.reposgrid
newRepo.targetV = newRepo.Status.MirrorTargetVersion()
grid.Append(newRepo.targetV)
newRepo.lastTag = newRepo.Status.MirrorLastTag()
grid.Append(newRepo.lastTag)
newRepo.currentName = newRepo.Status.MirrorCurrentName()
grid.Append(newRepo.currentName)
newRepo.currentVersion = newRepo.Status.MirrorCurrentVersion()
grid.Append(newRepo.currentVersion)
newRepo.gitState = newRepo.Status.MirrorGitState()
grid.Append(newRepo.gitState)
2024-02-29 21:57:33 -06:00
// newRepo.goState = grid.NewLabel("goState")
2024-02-22 19:28:23 -06:00
newRepo.endBox = grid.NewHorizontalBox("HBOX")
newRepo.endBox.NewButton("Configure", func() {
if newRepo.Status == nil {
// this should never happen, but it does happen because I'm not that smart and forget I can nil Status
// for some reason that makes sense in my head. again, I'm not that smart
log.Warn("status window wasn't created")
return
}
newRepo.Status.Toggle()
})
2024-02-29 21:57:33 -06:00
newRepo.endBox.NewButton("Whitelist", func() {
log.Info("need to implement this")
newRepo.Hide()
})
/*
2024-02-22 19:28:23 -06:00
newRepo.endBox.NewButton("CheckValidGoSum()", func() {
ok, err := r.CheckValidGoSum(newRepo)
if err != nil {
log.Info("go mod tidy did not work err =", err)
return
}
if ok {
log.Info("repo has go.sum requirements that are clean")
2024-02-29 21:57:33 -06:00
// newRepo.goState.SetText("GOOD")
2024-02-22 19:28:23 -06:00
return
}
})
2024-02-29 21:57:33 -06:00
*/
2024-02-22 19:28:23 -06:00
}