2024-01-09 15:34:53 -06:00
|
|
|
package repostatus
|
|
|
|
|
2024-01-18 00:57:43 -06:00
|
|
|
import (
|
2024-01-23 10:52:17 -06:00
|
|
|
"os"
|
|
|
|
|
2024-01-18 00:57:43 -06:00
|
|
|
"go.wit.com/lib/gadgets"
|
2024-11-29 23:18:46 -06:00
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
2024-01-18 00:57:43 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-09 15:34:53 -06:00
|
|
|
)
|
|
|
|
|
2024-01-21 03:18:07 -06:00
|
|
|
var windowMap map[string]*RepoStatus
|
|
|
|
|
2024-02-15 22:50:50 -06:00
|
|
|
func init() {
|
|
|
|
windowMap = make(map[string]*RepoStatus)
|
|
|
|
}
|
|
|
|
|
2024-02-18 15:09:48 -06:00
|
|
|
// deprecate this
|
|
|
|
func ListAllOld() {
|
2024-01-21 03:18:07 -06:00
|
|
|
for path, rs := range windowMap {
|
|
|
|
log.Warn(rs.GetMasterVersion(), path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-14 15:18:39 -06:00
|
|
|
// returns the object for the path
|
2024-02-18 15:09:48 -06:00
|
|
|
// deprecate this
|
|
|
|
func FindPathOld(path string) *RepoStatus {
|
2024-02-14 15:18:39 -06:00
|
|
|
if windowMap[path] == nil {
|
|
|
|
log.Log(INFO, "FindPath() not initialized yet", path)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return windowMap[path]
|
|
|
|
}
|
|
|
|
|
2024-03-07 19:31:52 -06:00
|
|
|
func SetWorkPath(path string) {
|
|
|
|
os.Setenv("REPO_WORK_PATH", path)
|
|
|
|
}
|
2024-02-19 14:42:59 -06:00
|
|
|
|
2024-11-28 18:36:29 -06:00
|
|
|
// makes a window of the status of the repo
|
|
|
|
// don't worry, you can think of it like Sierpinski carpet
|
|
|
|
// it's doesn't need to be displayed so it'll work fine even in an embedded space
|
|
|
|
func NewRepoStatusWindow(repo *gitpb.Repo) (*RepoStatus, error) {
|
|
|
|
path := repo.GoPath
|
2024-03-07 19:31:52 -06:00
|
|
|
if windowMap[path] == nil {
|
|
|
|
log.Log(INFO, "NewRepoStatusWindow() adding new", path)
|
|
|
|
} else {
|
|
|
|
log.Warn("This already exists for path", path)
|
|
|
|
log.Warn("should return windowMap[path] here")
|
2024-11-28 18:36:29 -06:00
|
|
|
return windowMap[path], nil
|
2024-03-07 19:31:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
rs := &RepoStatus{
|
|
|
|
ready: false,
|
|
|
|
}
|
2024-12-03 00:34:55 -06:00
|
|
|
rs.pb = repo
|
|
|
|
// realpath := repo.FullPath
|
|
|
|
// isGoLang := true
|
2024-03-07 19:31:52 -06:00
|
|
|
|
2024-02-14 02:35:47 -06:00
|
|
|
rs.tags = make(map[string]string)
|
|
|
|
rs.window = gadgets.RawBasicWindow("GO Repo Details " + path)
|
|
|
|
rs.window.Horizontal()
|
|
|
|
rs.window.Make()
|
2024-02-15 22:50:50 -06:00
|
|
|
basebox := rs.window.Box()
|
|
|
|
group := basebox.NewGroup("stuff")
|
|
|
|
primarybox := group.Box()
|
|
|
|
primarybox.Horizontal()
|
|
|
|
box2 := group.Box()
|
2024-02-14 02:35:47 -06:00
|
|
|
rs.ready = true
|
|
|
|
rs.window.Custom = func() {
|
|
|
|
rs.Hide()
|
|
|
|
log.Warn("repostatus user closed the window()")
|
|
|
|
}
|
2024-02-15 22:50:50 -06:00
|
|
|
|
|
|
|
// display the status of the git repository
|
|
|
|
rs.drawGitStatus(primarybox)
|
|
|
|
|
|
|
|
// display the git branches and options
|
|
|
|
rs.makeBranchesBox(primarybox)
|
|
|
|
|
|
|
|
// show standard git commit and merge controls
|
|
|
|
rs.drawGitCommands(primarybox)
|
2024-01-23 10:52:17 -06:00
|
|
|
|
|
|
|
// save ~/go/src & the whole path strings
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.path.SetValue(path)
|
2024-12-03 00:34:55 -06:00
|
|
|
rs.goSrcPath.SetValue(os.Getenv("FORGE_GOSRC"))
|
|
|
|
rs.realPath.SetValue(rs.pb.GetFullPath())
|
2024-01-23 10:52:17 -06:00
|
|
|
|
2024-02-15 22:50:50 -06:00
|
|
|
// add all the tags
|
|
|
|
rs.makeTagBox(box2)
|
|
|
|
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.readGitConfig()
|
|
|
|
|
2024-12-03 00:34:55 -06:00
|
|
|
if rs.pb.GetReadOnly() {
|
|
|
|
rs.readOnly.SetValue("true")
|
|
|
|
} else {
|
2024-01-23 22:47:39 -06:00
|
|
|
rs.readOnly.SetValue("false")
|
|
|
|
}
|
2024-12-03 00:34:55 -06:00
|
|
|
rs.mainWorkingName.SetText(rs.pb.GetMasterBranchName())
|
|
|
|
rs.mainBranchVersion.SetLabel(rs.pb.GetMasterBranchName())
|
|
|
|
|
|
|
|
rs.develWorkingName.SetText(rs.pb.GetDevelBranchName())
|
|
|
|
rs.develBranchVersion.SetLabel(rs.pb.GetDevelBranchName())
|
2024-02-16 11:41:29 -06:00
|
|
|
|
2024-12-03 00:34:55 -06:00
|
|
|
rs.userWorkingName.SetText(rs.pb.GetUserBranchName())
|
|
|
|
rs.userBranchVersion.SetLabel(rs.pb.GetUserBranchName())
|
2024-01-23 10:52:17 -06:00
|
|
|
|
2024-12-03 00:34:55 -06:00
|
|
|
if rs.pb.GoPath == "" {
|
|
|
|
// not golang repo
|
|
|
|
} else {
|
2024-02-19 14:42:59 -06:00
|
|
|
rs.isGoLang.SetText("true")
|
2024-12-03 00:34:55 -06:00
|
|
|
rs.goPath.SetText(rs.pb.GoPath)
|
2024-02-19 14:42:59 -06:00
|
|
|
}
|
2024-01-21 03:18:07 -06:00
|
|
|
windowMap[path] = rs
|
2024-11-28 18:36:29 -06:00
|
|
|
return rs, nil
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|