2024-02-17 14:20:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
"go.wit.com/lib/gui/repolist"
|
2025-01-07 05:36:03 -06:00
|
|
|
"go.wit.com/lib/protobuf/forgepb"
|
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
2024-02-17 14:20:37 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
|
|
|
|
"go.wit.com/gui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type repoWindow struct {
|
2024-02-19 19:41:48 -06:00
|
|
|
win *gadgets.BasicWindow
|
|
|
|
box *gui.Node
|
|
|
|
|
|
|
|
// the top box of the repolist window
|
|
|
|
topbox *gui.Node
|
|
|
|
|
2024-02-17 14:20:37 -06:00
|
|
|
View *repolist.RepoList
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repoWindow) Hidden() bool {
|
|
|
|
return r.win.Hidden()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repoWindow) Show() {
|
|
|
|
r.win.Show()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repoWindow) Hide() {
|
|
|
|
r.win.Hide()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repoWindow) Disable() {
|
|
|
|
r.box.Disable()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repoWindow) Enable() {
|
|
|
|
r.box.Enable()
|
|
|
|
}
|
|
|
|
|
|
|
|
// you can only have one of these
|
|
|
|
func makeRepoView() *repoWindow {
|
|
|
|
if me.repos != nil {
|
|
|
|
return me.repos
|
|
|
|
}
|
|
|
|
r := new(repoWindow)
|
|
|
|
r.win = gadgets.RawBasicWindow("All git repositories in ~/go/src/")
|
|
|
|
r.win.Make()
|
|
|
|
|
|
|
|
r.box = r.win.Box().NewBox("bw vbox", false)
|
|
|
|
// me.reposwin.Draw()
|
|
|
|
r.win.Custom = func() {
|
|
|
|
log.Warn("GOT HERE: main() gadgets.NewBasicWindow() close")
|
|
|
|
log.Warn("Should I do something special here?")
|
|
|
|
}
|
|
|
|
|
2024-12-02 06:59:56 -06:00
|
|
|
r.topbox = r.repoMenu()
|
2024-02-17 14:20:37 -06:00
|
|
|
|
2024-12-02 06:59:56 -06:00
|
|
|
r.View = repolist.InitBox(me.forge, r.box)
|
|
|
|
r.View.Enable()
|
2024-02-17 14:20:37 -06:00
|
|
|
|
2024-12-02 06:59:56 -06:00
|
|
|
r.View.ScanRepositories()
|
|
|
|
return r
|
2024-02-17 14:20:37 -06:00
|
|
|
}
|
|
|
|
|
2025-01-07 19:30:25 -06:00
|
|
|
func (r *repoWindow) reInitForge() {
|
|
|
|
// re-read everything
|
|
|
|
me.forge = forgepb.Init()
|
|
|
|
me.found = new(gitpb.Repos)
|
|
|
|
me.repos = makeRepoView()
|
|
|
|
me.repos.Show()
|
|
|
|
|
|
|
|
// update the protobuf pointers
|
|
|
|
loop := me.forge.Repos.All()
|
|
|
|
for loop.Scan() {
|
|
|
|
repo := loop.Next()
|
|
|
|
vrepo := me.repos.View.FindByPath(repo.GetGoPath())
|
|
|
|
if vrepo != nil {
|
|
|
|
vrepo.UpdatePb(repo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now update the gui
|
|
|
|
vloop := me.repos.View.ReposSortByName()
|
|
|
|
for vloop.Scan() {
|
|
|
|
var repo *repolist.RepoRow
|
|
|
|
repo = vloop.Repo()
|
|
|
|
repo.NewScan()
|
|
|
|
}
|
|
|
|
|
|
|
|
i, s := me.repos.View.ScanRepositories()
|
|
|
|
log.Info("re-scanning done", i, "repos in", s)
|
|
|
|
}
|
|
|
|
|
2024-12-02 06:59:56 -06:00
|
|
|
func (r *repoWindow) repoMenu() *gui.Node {
|
2024-02-17 14:20:37 -06:00
|
|
|
// reposbox.SetExpand(false)
|
2024-12-23 11:15:16 -06:00
|
|
|
group1 := r.box.NewGroup("Filter:")
|
2024-02-17 14:20:37 -06:00
|
|
|
|
|
|
|
hbox := group1.Box()
|
|
|
|
// hbox.Horizontal()
|
|
|
|
hbox.Vertical()
|
|
|
|
|
2024-12-23 11:15:16 -06:00
|
|
|
box2 := hbox.Box().Horizontal()
|
2024-12-02 06:59:56 -06:00
|
|
|
/*
|
2024-12-23 11:15:16 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
dirty := box2.NewCheckbox("dirty")
|
|
|
|
dirty.Custom = func() {
|
|
|
|
log.Info("filter dirty =", dirty.Checked())
|
|
|
|
}
|
2024-02-17 14:20:37 -06:00
|
|
|
|
2025-01-07 03:23:35 -06:00
|
|
|
box2.NewButton("merge user to devel", func() {
|
2024-02-17 14:20:37 -06:00
|
|
|
r.Disable()
|
2025-01-05 12:13:32 -06:00
|
|
|
if IsAnythingDirty() {
|
|
|
|
log.Info("You can't apply patches when repos are dirty")
|
|
|
|
doCobol()
|
|
|
|
return
|
|
|
|
}
|
2024-02-17 14:20:37 -06:00
|
|
|
if !r.mergeAllUserToDevel() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r.Enable()
|
|
|
|
})
|
|
|
|
|
2025-01-07 04:51:42 -06:00
|
|
|
box2.NewButton("test master merge", func() {
|
|
|
|
r.Disable()
|
2025-01-07 06:14:47 -06:00
|
|
|
r.mergeAllDevelToMain()
|
2025-01-07 19:30:25 -06:00
|
|
|
r.reInitForge()
|
2025-01-07 04:51:42 -06:00
|
|
|
r.Enable()
|
|
|
|
})
|
|
|
|
|
2024-12-02 06:59:56 -06:00
|
|
|
box2.NewButton("show apps", func() {
|
2024-11-16 00:07:00 -06:00
|
|
|
loop := me.repos.View.ReposSortByName()
|
|
|
|
for loop.Scan() {
|
2025-01-07 04:51:42 -06:00
|
|
|
var repo *repolist.RepoRow
|
|
|
|
repo = loop.Repo()
|
|
|
|
if repo.IsBinary() {
|
2024-12-02 06:59:56 -06:00
|
|
|
// log.Info(repo.Status.Path(), "compile here. Show()")
|
|
|
|
repo.Show()
|
2025-01-07 04:51:42 -06:00
|
|
|
} else {
|
2024-12-02 06:59:56 -06:00
|
|
|
// log.Info(repo.Status.Path(), "library here. Hide()")
|
|
|
|
repo.Hide()
|
2024-02-17 14:20:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2025-01-07 19:30:25 -06:00
|
|
|
box2.NewButton("re-init forge", func() {
|
2024-12-02 06:59:56 -06:00
|
|
|
log.Info("re-scanning now")
|
2025-01-07 19:30:25 -06:00
|
|
|
r.reInitForge()
|
2024-12-02 06:59:56 -06:00
|
|
|
})
|
|
|
|
|
2024-02-19 19:41:48 -06:00
|
|
|
return box2
|
2024-02-17 14:20:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repoWindow) mergeAllDevelToMain() bool {
|
|
|
|
log.Info("merge all here")
|
2025-01-05 12:02:19 -06:00
|
|
|
loop := me.forge.Repos.All()
|
2024-11-16 00:07:00 -06:00
|
|
|
for loop.Scan() {
|
2025-01-05 12:02:19 -06:00
|
|
|
repo := loop.Next()
|
|
|
|
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
|
2025-01-07 20:28:40 -06:00
|
|
|
// log.Info("skipping readonly", repo.GetFullPath())
|
2024-02-17 14:20:37 -06:00
|
|
|
continue
|
|
|
|
}
|
2025-01-05 12:02:19 -06:00
|
|
|
if repo.IsDirty() {
|
|
|
|
log.Info("skipping dirty", repo.GetFullPath())
|
2024-02-17 14:20:37 -06:00
|
|
|
continue
|
|
|
|
}
|
2025-01-07 20:28:40 -06:00
|
|
|
if repo.GetDevelVersion() != repo.GetUserVersion() {
|
|
|
|
log.Info("devel and user branch are different", repo.GetFullPath())
|
2025-01-05 12:18:53 -06:00
|
|
|
continue
|
|
|
|
}
|
2025-01-07 04:51:42 -06:00
|
|
|
if repo.GetDevelVersion() == repo.GetMasterVersion() {
|
2025-01-07 20:28:40 -06:00
|
|
|
// log.Info("devel and master branch are the same", repo.GetFullPath())
|
2024-02-17 14:20:37 -06:00
|
|
|
continue
|
2025-01-07 04:51:42 -06:00
|
|
|
}
|
|
|
|
if result, err := repo.MergeDevelToMaster(); err == nil {
|
2025-01-07 06:51:58 -06:00
|
|
|
log.Warn("MERGE WORKED", repo.GetFullPath())
|
2025-01-07 20:28:40 -06:00
|
|
|
// continue
|
|
|
|
return true
|
2024-02-17 14:20:37 -06:00
|
|
|
} else {
|
2025-01-05 12:02:19 -06:00
|
|
|
log.Warn("THINGS FAILED ", repo.GetFullPath())
|
|
|
|
log.Warn("err", err)
|
|
|
|
for _, line := range result.Stdout {
|
|
|
|
log.Warn("stdout:", line)
|
|
|
|
}
|
|
|
|
for _, line := range result.Stderr {
|
|
|
|
log.Warn("stderr:", line)
|
|
|
|
}
|
2024-02-17 14:20:37 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Warn("EVERYTHING WORKED")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *repoWindow) mergeAllUserToDevel() bool {
|
|
|
|
log.Info("merge all here")
|
2025-01-05 12:02:19 -06:00
|
|
|
loop := me.forge.Repos.All()
|
2024-11-16 00:07:00 -06:00
|
|
|
for loop.Scan() {
|
2025-01-05 12:02:19 -06:00
|
|
|
repo := loop.Next()
|
|
|
|
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
|
2025-01-05 12:18:53 -06:00
|
|
|
// log.Info("skipping readonly", repo.GetFullPath())
|
2024-02-17 14:20:37 -06:00
|
|
|
continue
|
|
|
|
}
|
2025-01-05 12:02:19 -06:00
|
|
|
if repo.IsDirty() {
|
|
|
|
log.Info("skipping dirty", repo.GetFullPath())
|
2024-02-17 14:20:37 -06:00
|
|
|
continue
|
|
|
|
}
|
2025-01-05 12:18:53 -06:00
|
|
|
if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
|
|
|
|
log.Info("not on user branch", repo.GetFullPath())
|
|
|
|
continue
|
|
|
|
}
|
2025-01-05 12:02:19 -06:00
|
|
|
if result, err := repo.MergeUserToDevel(); err == nil {
|
|
|
|
log.Warn("THINGS SEEM OK", repo.GetFullPath())
|
2025-01-07 21:31:31 -06:00
|
|
|
repo.Reload()
|
|
|
|
vrepo := me.repos.View.FindByPath(repo.GetGoPath())
|
|
|
|
if vrepo != nil {
|
|
|
|
vrepo.UpdatePb(repo)
|
|
|
|
vrepo.NewScan()
|
|
|
|
}
|
2024-02-17 14:20:37 -06:00
|
|
|
continue
|
|
|
|
} else {
|
2025-01-05 12:02:19 -06:00
|
|
|
log.Warn("THINGS FAILED ", repo.GetFullPath())
|
|
|
|
log.Warn("err", err)
|
|
|
|
for _, line := range result.Stdout {
|
|
|
|
log.Warn("stdout:", line)
|
|
|
|
}
|
|
|
|
for _, line := range result.Stderr {
|
|
|
|
log.Warn("stderr:", line)
|
|
|
|
}
|
2024-02-17 14:20:37 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Warn("EVERYTHING WORKED")
|
|
|
|
return true
|
|
|
|
}
|