258 lines
6.2 KiB
Go
258 lines
6.2 KiB
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"os/user"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"go.wit.com/gui"
|
|
"go.wit.com/lib/gadgets"
|
|
"go.wit.com/lib/gui/repostatus"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
// deprecate
|
|
func (r *repo) StringOld() string {
|
|
return r.status.String()
|
|
}
|
|
|
|
/*
|
|
func (r *repo) getPath() string {
|
|
return r.path
|
|
}
|
|
*/
|
|
|
|
func RemoveFirstElement(slice []string) (string, []string) {
|
|
if len(slice) == 0 {
|
|
return "", slice // Return the original slice if it's empty
|
|
}
|
|
return slice[0], slice[1:] // Return the slice without the first element
|
|
}
|
|
|
|
// returns path, master branch name, devel branch name, user branch name
|
|
func splitLine(line string) (string, string, string, string) {
|
|
var path, master, devel, user string
|
|
parts := strings.Split(line, " ")
|
|
path, parts = RemoveFirstElement(parts)
|
|
master, parts = RemoveFirstElement(parts)
|
|
devel, parts = RemoveFirstElement(parts)
|
|
user, parts = RemoveFirstElement(parts)
|
|
// path, master, devel, user := strings.Split(line, " ")
|
|
return path, master, devel, user
|
|
}
|
|
|
|
func myrepolist() []string {
|
|
homeDir, _ := os.UserHomeDir()
|
|
cfgfile := filepath.Join(homeDir, ".config/autotypist")
|
|
content, _ := ioutil.ReadFile(cfgfile)
|
|
out := string(content)
|
|
out = strings.TrimSpace(out)
|
|
lines := strings.Split(out, "\n")
|
|
return lines
|
|
}
|
|
|
|
// This creates a window
|
|
func repolistWindow() {
|
|
me.reposwin = gadgets.NewBasicWindow(me.myGui, "All git repositories in ~/go/src/")
|
|
me.reposwin.Make()
|
|
|
|
me.reposbox = me.reposwin.Box().NewBox("bw vbox", false)
|
|
// me.reposwin.Draw()
|
|
me.reposwin.Custom = func() {
|
|
log.Warn("GOT HERE: main() gadgets.NewBasicWindow() close")
|
|
log.Warn("Should I do something special here?")
|
|
}
|
|
|
|
repoAllButtons(me.reposbox)
|
|
|
|
me.reposgroup = me.reposbox.NewGroup("git repositories (configure in ~/.config/myrepolist)")
|
|
me.reposgrid = me.reposgroup.NewGrid("test", 0, 0)
|
|
|
|
me.reposgrid.NewLabel("") // path goes here
|
|
|
|
me.reposgrid.NewLabel("last tag").SetProgName("last tag")
|
|
|
|
me.reposgrid.NewLabel("master version")
|
|
me.reposgrid.NewLabel("devel version")
|
|
me.reposgrid.NewLabel("user version")
|
|
|
|
me.reposgrid.NewLabel("Status")
|
|
|
|
me.reposgrid.NewLabel("Current Version").SetProgName("Current Version")
|
|
me.reposgrid.NextRow()
|
|
|
|
usr, _ := user.Current()
|
|
|
|
repos := myrepolist()
|
|
for _, line := range repos {
|
|
log.Verbose("repo =", line)
|
|
path, mbranch, dbranch, ubranch := splitLine(line)
|
|
if mbranch == "" {
|
|
mbranch = "master"
|
|
}
|
|
if dbranch == "" {
|
|
dbranch = "devel"
|
|
}
|
|
if ubranch == "" {
|
|
ubranch = usr.Username
|
|
}
|
|
newrepo := addRepo(me.reposgrid, path, mbranch, dbranch, ubranch)
|
|
if newrepo != nil {
|
|
// assume repos from ~/.config/autotypist file might be modified
|
|
newrepo.status.Writable()
|
|
}
|
|
me.reposgrid.NextRow()
|
|
}
|
|
|
|
if args.OnlyMe {
|
|
log.Info("not scanning everything")
|
|
} else {
|
|
log.Info("scanning everything in ~/go/src")
|
|
for i, path := range repostatus.ListGitDirectories() {
|
|
// log.Info("addRepo()", i, path)
|
|
tmp := strings.TrimPrefix(path, me.goSrcPwd.String())
|
|
path = strings.Trim(tmp, "/")
|
|
log.Info("addRepo()", i, path)
|
|
addRepo(me.reposgrid, path, "master", "devel", usr.Username)
|
|
me.reposgrid.NextRow()
|
|
}
|
|
}
|
|
}
|
|
|
|
func showApps() {
|
|
for _, repo := range me.allrepos {
|
|
switch repo.status.RepoType() {
|
|
case "binary":
|
|
//log.Info("compile here. Show()")
|
|
repo.Show()
|
|
case "library":
|
|
//log.Info("library here. Hide()")
|
|
repo.Hide()
|
|
default:
|
|
log.Info("showApps() unknown. Show()")
|
|
repo.Hide()
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
func repoAllButtons(box *gui.Node) {
|
|
// reposbox.SetExpand(false)
|
|
group1 := box.NewGroup("Run on all repos:")
|
|
|
|
hbox := group1.Box()
|
|
// hbox.Horizontal()
|
|
hbox.Vertical()
|
|
|
|
box2 := hbox.Box().Vertical()
|
|
box2.NewButton("merge all user to devel", func() {
|
|
me.reposwin.Disable()
|
|
if !mergeAllUserToDevel() {
|
|
return
|
|
}
|
|
me.reposwin.Enable()
|
|
})
|
|
|
|
box2.NewButton("merge all devel to main", func() {
|
|
me.reposwin.Disable()
|
|
if !mergeAllDevelToMain() {
|
|
return
|
|
}
|
|
me.reposwin.Enable()
|
|
})
|
|
|
|
box2.NewButton("merge it all", func() {
|
|
me.reposwin.Disable()
|
|
if !mergeAllUserToDevel() {
|
|
return
|
|
}
|
|
if !mergeAllDevelToMain() {
|
|
return
|
|
}
|
|
me.reposwin.Enable()
|
|
})
|
|
|
|
box2.NewButton("test all builds", func() {
|
|
me.reposwin.Disable()
|
|
defer me.reposwin.Enable()
|
|
showApps()
|
|
for _, repo := range me.allrepos {
|
|
if repo.Hidden() {
|
|
// log.Info("skip hidden", repo.String())
|
|
} else {
|
|
log.Info("try to build", repo.String())
|
|
if repo.status.Build() {
|
|
log.Info("build worked", repo.String())
|
|
} else {
|
|
log.Info("build failed", repo.String())
|
|
go repo.status.Xterm("bash")
|
|
return
|
|
}
|
|
}
|
|
}
|
|
log.Info("")
|
|
log.Info("every build worked !!!")
|
|
log.Info("")
|
|
})
|
|
}
|
|
|
|
func mergeAllDevelToMain() bool {
|
|
log.Info("merge all here")
|
|
for _, repo := range me.allrepos {
|
|
if repo.status.ReadOnly() {
|
|
log.Info("skipping readonly", repo.String(), repo.dirtyLabel.String())
|
|
continue
|
|
}
|
|
if repo.dirtyLabel.String() != "merge to main" {
|
|
log.Info("skipping. not merge to main", repo.String(), repo.dirtyLabel.String())
|
|
continue
|
|
}
|
|
if repo.status.CheckDirty() {
|
|
log.Info("skipping dirty", repo.String(), repo.dirtyLabel.String())
|
|
continue
|
|
}
|
|
log.Info("found", repo.String(), repo.dirtyLabel.String())
|
|
repo.newScan()
|
|
if repo.status.RunDevelMergeB() {
|
|
log.Warn("THINGS SEEM OK fullAutomation() returned true.")
|
|
} else {
|
|
log.Warn("THINGS FAILED fullAutomation() returned false")
|
|
return false
|
|
}
|
|
repo.newScan()
|
|
}
|
|
log.Warn("EVERYTHING WORKED")
|
|
return true
|
|
}
|
|
|
|
func mergeAllUserToDevel() bool {
|
|
log.Info("merge all here")
|
|
for _, repo := range me.allrepos {
|
|
if repo.status.ReadOnly() {
|
|
log.Info("skipping readonly", repo.String(), repo.dirtyLabel.String())
|
|
continue
|
|
}
|
|
if repo.dirtyLabel.String() != "merge to devel" {
|
|
log.Info("skipping. not merge to devel", repo.String(), repo.dirtyLabel.String())
|
|
continue
|
|
}
|
|
if repo.status.CheckDirty() {
|
|
log.Info("skipping dirty", repo.String(), repo.dirtyLabel.String())
|
|
continue
|
|
}
|
|
log.Info("found", repo.String(), repo.dirtyLabel.String())
|
|
repo.newScan()
|
|
if repo.status.RunDevelMergeB() {
|
|
log.Warn("THINGS SEEM OK fullAutomation() returned true.")
|
|
} else {
|
|
log.Warn("THINGS FAILED fullAutomation() returned false")
|
|
return false
|
|
}
|
|
repo.newScan()
|
|
}
|
|
log.Warn("EVERYTHING WORKED")
|
|
return true
|
|
}
|