// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main // An app to submit patches for the 30 GO GUI repos import ( "fmt" "os" "time" "go.wit.com/gui" "go.wit.com/lib/debugger" "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func debug() { time.Sleep(2 * time.Second) for { var found *gitpb.Repos now := time.Now() tmp := fmt.Sprintf("All (%d)", me.forge.Repos.Len()) me.repoAllB.SetLabel(tmp) found = findMergeToDevel() tmp = fmt.Sprintf("needs merge to devel (%d)", found.Len()) me.repoDevelMergeB.SetLabel(tmp) found = gitpb.NewRepos() all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() if me.forge.Config.IsReadOnly(repo.GetGoPath()) { continue } found.AppendByGoPath(repo) } tmp = fmt.Sprintf("writable (%d)", found.Len()) me.repoWritableB.SetLabel(tmp) doCheckDirtyAndConfigSave() found = findDirty() tmp = fmt.Sprintf("dirty (%d)", found.Len()) me.repoDirtyB.SetLabel(tmp) log.Printf("finished a forge scan here in (%s)\n", shell.FormatDuration(time.Since(now))) time.Sleep(90 * time.Second) } } func doGui() { if me.forge.Config.GetDefaultGui() == "" { me.forge.Config.DefaultGui = "gocui" me.forge.ConfigSave() } me.myGui = gui.New() me.myGui.InitEmbed(resources) me.myGui.SetAppDefaultPlugin(me.forge.Config.DefaultGui) // sets the default GUI plugin to use me.myGui.Default() mainWindow := gadgets.RawBasicWindow("Forge: (this kinda works sometimes)") mainWindow.Make() mainWindow.Show() mainWindow.Custom = func() { log.Warn("MAIN WINDOW CLOSE") now := time.Now() count := me.forge.RillReload() log.Info("Repo Reload count =", count) if count != 0 { me.forge.ConfigSave() } log.Printf("rill repos.Reload() took (%s)\n", shell.FormatDuration(time.Since(now))) os.Exit(0) } drawWindow(mainWindow) // sits here forever debug() } func drawWindow(win *gadgets.BasicWindow) { box := win.Box() vbox := box.NewVerticalBox("BOX2") group1 := vbox.NewGroup("Forge Settings") grid := group1.NewGrid("buildOptions", 0, 0) // me.autoWorkingPwd = gadgets.NewOneLiner(grid, "working directory (pwd)") me.goSrcPwd = gadgets.NewOneLiner(grid, "repo src home") grid.NewLabel("") var howtoWin *GenericWindow me.demoB = grid.NewButton("Howto", func() { if howtoWin != nil { howtoWin.Toggle() return } howtoWin = makeHowtoWin() }) grid.NextRow() me.goSrcPwd.SetText(me.forge.GetGoSrc()) // use ENV GIT_AUTHOR me.gitAuthor = gadgets.NewOneLiner(grid, "Git Author") grid.NextRow() if os.Getenv("GIT_AUTHOR_NAME") == "" { me.gitAuthor.SetText("ENV GIT_AUTHOR_NAME is unset") } else { author := os.Getenv("GIT_AUTHOR_NAME") author += " <" + os.Getenv("GIT_AUTHOR_EMAIL") + ">" me.gitAuthor.SetText(author) } // select the branch you want to test, build and develop against // this lets you select your user branch, but, when you are happy // you can merge everything into the devel branch and make sure it actually // works. Then, when that is good, merge and version everything in master me.setBranchB = grid.NewButton("git checkout", func() { win.Disable() defer win.Enable() if me.autoCreateBranches.Checked() { argv.Force = true } else { argv.Force = false } // do the checkout if err := doCheckoutShared(); err != nil { log.Info("checkout error:", err) } else { log.Info("checkout was ok") } }) /* me.setBranchB = grid.NewButton("git repos", func() { t := me.forge.Repos.NewTable() fp := t.AddFullPath("Full Path") fp.Custom( func() { log.Info("this is the full path") }) t.AddMasterVersion("master version") t.Show() }) */ me.newBranch = grid.NewDropdown() me.newBranch.AddText("master") me.newBranch.AddText("devel") me.newBranch.AddText(me.forge.Config.GetUsername()) me.newBranch.SetText(me.forge.Config.GetUsername()) me.argvCheckoutUser = true me.newBranch.Custom = func() { // toggle global values shared by the command line and the gui for doCheckout() me.argvCheckoutUser = false me.argvCheckoutDevel = false me.argvCheckoutMaster = false switch me.newBranch.String() { case "master": me.argvCheckoutMaster = true case "devel": me.argvCheckoutDevel = true default: me.argvCheckoutUser = true } log.Info("forged changed to default:", me.newBranch.String()) } // checking this will automatically make the branches off of devel me.autoCreateBranches = grid.NewCheckbox("auto create branches").SetChecked(true) grid.NextRow() group2 := vbox.NewGroup("Repos") grid = group2.RawGrid() me.repoDirtyB = grid.NewButton("dirty", func() { doCheckDirtyAndConfigSave() found := findDirty() _, box := makeStandardReposWindow("dirty repos", found) hbox := box.Box().Horizontal() hbox.NewButton("commit all", func() { all := found.SortByFullPath() for all.Scan() { repo := all.Next() log.Info("do commit here on", repo.GetGoPath()) } log.Info("TODO: fix this") log.Info("run 'forge commit --all'") }) }) me.repoWritableB = grid.NewButton("writable", func() { me.found = new(gitpb.Repos) all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() if me.forge.Config.IsReadOnly(repo.GetGoPath()) { continue } me.found.AppendByGoPath(repo) } makeStandardReposWindow("Repos that you have write access to", me.found) }) me.repoAllB = grid.NewButton("All", func() { me.found = new(gitpb.Repos) all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() me.found.AppendByGoPath(repo) } makeStandardReposWindow("All repos", me.found) }) me.repoDevelMergeB = grid.NewButton("merge", func() { found := findMergeToDevel() _, box := makeStandardReposWindow("repos to merge from user to devel", found) hbox := box.Box().Horizontal() hbox.NewButton("merge all", func() { win.Disable() defer win.Enable() all := found.SortByFullPath() for all.Scan() { repo := all.Next() if repo.CheckDirty() { log.Info("repo is dirty", repo.GetGoPath()) continue } log.Info("Starting merge on", repo.GetGoPath()) if repo.CheckoutDevel() { log.Info("checkout devel failed", repo.GetGoPath()) return } if _, err := repo.MergeToDevel(); err != nil { log.Info("merge from user failed", repo.GetGoPath(), err) // log.Info(strings.Join(r.Stdout, "\n")) // log.Info(strings.Join(r.Stderr, "\n")) return } if repo.CheckoutMaster() { log.Info("checkout master failed", repo.GetGoPath()) return } if _, err := repo.MergeToMaster(); err != nil { log.Info("merge from devel failed", repo.GetGoPath(), err) return } } }) }) var problemsWin *repoProblemsWindow grid.NewButton("Repo Problems", func() { if problemsWin != nil { problemsWin.Toggle() return } problemsWin = makeRepoProblemsWindow() }) grid.NextRow() group2 = vbox.NewGroup("Merge") grid = group2.RawGrid() grid.NewButton("merge to devel", func() { win.Disable() defer win.Enable() mergeUserToDevel(me.autoCreateBranches.Checked()) }) grid.NewButton("merge to master", func() { win.Disable() defer win.Enable() mergeDevelToMaster(me.autoCreateBranches.Checked()) }) grid.NewButton("merge all", func() { win.Disable() defer win.Enable() me.argvCheckoutUser = false me.argvCheckoutDevel = true me.argvCheckoutMaster = false if err := doCheckoutShared(); err != nil { log.Info("checkout error:", err) } else { log.Info("checkout was ok") } mergeUserToDevel(me.autoCreateBranches.Checked()) me.argvCheckoutUser = false me.argvCheckoutDevel = false me.argvCheckoutMaster = true if err := doCheckoutShared(); err != nil { log.Info("checkout error:", err) } else { log.Info("checkout was ok") } mergeDevelToMaster(me.autoCreateBranches.Checked()) }) group3 := vbox.NewGroup("work in progress") grid = group3.RawGrid() grid.NewButton("forge ConfigSave()", func() { me.forge.ConfigSave() }) grid.NewButton("debugger()", func() { debugger.DebugWindow() }) var patchWin *patchesWindow grid.NewButton("Patches Window", func() { if patchWin != nil { patchWin.Toggle() return } patchWin = new(patchesWindow) patchWin.initWindow() patchWin.Show() }) } // this is the magic that generates a window directly from the protocol buffer func makeStandardReposGrid(pb *gitpb.Repos) *gitpb.ReposTable { t := pb.NewTable("testDirty") sf := t.AddStringFunc("repo", func(r *gitpb.Repo) string { return r.GetGoPath() }) // t.Custom = func() { // log.Info("close grid?") // } sf.Custom = func(r *gitpb.Repo) { log.Info("do button click on", r.GetGoPath()) } t.AddTimeFunc("age", func(repo *gitpb.Repo) time.Time { return repo.NewestTime() }) t.AddMasterVersion() t.AddDevelVersion() t.AddUserVersion() t.AddCurrentBranchName() t.AddState() return t } // this is the magic that generates a window directly from the protocol buffer func makeStandardReposWindow(title string, pb *gitpb.Repos) (*gitpb.ReposTable, *gui.Node) { win := gadgets.RawBasicWindow(title) win.Make() win.Show() win.Custom = func() { // sets the hidden flag to false so Toggle() works win.Hide() } box := win.Box().NewBox("bw vbox", false) t := makeStandardReposGrid(pb) t.SetParent(box) t.ShowTable() return t, box } func findMergeToDevel() *gitpb.Repos { found := gitpb.NewRepos() all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() // this sees if user has patches for devel. If it does, add it to me.found if repo.CountDiffObjects(repo.GetUserBranchName(), repo.GetDevelBranchName()) > 0 { found.AppendByGoPath(repo) } } now := time.Now() if found.Len() == 0 { log.Info("nothing to merge with devel") return found } // me.forge.PrintHumanTable(found) // check for merges from devel total, count, nope, _ := IsEverythingOnDevel() log.Printf("devel branch check. %d total repos. (%d ok) (%d not on devel branch) (%s)\n", total, count, nope, shell.FormatDuration(time.Since(now))) return found } func findMergeToMaster() { me.found = new(gitpb.Repos) all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() if me.forge.Config.IsReadOnly(repo.GetGoPath()) { continue } /* if repo.IsDirty() { continue } if repo.GetMasterVersion() != repo.GetDevelVersion() { me.found.AppendByGoPath(repo) continue } */ // this sees if devel is behind master. IT SHOULD NOT BE if repo.CountDiffObjects(repo.GetMasterBranchName(), repo.GetDevelBranchName()) == 0 { // everything is normal } else { repo.State = "DEVEL < MASTER" log.Info("SERIOUS ERROR. DEVEL BRANCH IS BEHIND MASTER", repo.GetGoPath()) } // this sees if devel has patches for master. If it does, add it to me.found if repo.CountDiffObjects(repo.GetDevelBranchName(), repo.GetMasterBranchName()) > 0 { me.found.AppendByGoPath(repo) } } now := time.Now() if me.found.Len() == 0 { log.Info("nothing to merge with master") return } me.forge.PrintHumanTable(me.found) // check for merges from devel total, count, nope, _ := IsEverythingOnMaster() log.Printf("Master branch check. %d total repos. (%d ok) (%d not on master branch) (%s)\n", total, count, nope, shell.FormatDuration(time.Since(now))) } func mergeDevelToMaster(doit bool) { findMergeToMaster() if !doit { return } all := me.found.SortByFullPath() for all.Scan() { repo := all.Next() log.Info("repo:", repo.GetGoPath()) if result, err := repo.MergeToMaster(); err == nil { log.Warn("THINGS SEEM OK", repo.GetFullPath()) for _, line := range result.Stdout { log.Warn("stdout:", line) } for _, line := range result.Stderr { log.Warn("stderr:", line) } } else { log.Warn("THINGS FAILED ", repo.GetFullPath()) log.Warn("err", err) if result == nil { break } for _, line := range result.Stdout { log.Warn("stdout:", line) } for _, line := range result.Stderr { log.Warn("stderr:", line) } log.Warn("THINGS FAILED ", repo.GetFullPath()) break } me.forge.SetConfigSave(true) // view.Update() } me.forge.ConfigSave() } func mergeUserToDevel(doit bool) { found := findMergeToDevel() if !doit { return } all := found.SortByFullPath() for all.Scan() { repo := all.Next() bruser := repo.GetUserBranchName() brdevel := repo.GetDevelBranchName() if repo.GetUserVersion() == "uerr" { // no user branch return } log.Info("trying", bruser, repo.GetUserVersion()) b1 := repo.CountDiffObjects(bruser, brdevel) // should be zero if b1 == 0 { // log.Info("User is already merged into Devel", repo.GetGoPath(), cmd) return } log.Info("merging user into devel repo:", repo.GetGoPath()) if result, err := repo.MergeToDevel(); err == nil { log.Warn("THINGS SEEM OK", repo.GetFullPath()) for _, line := range result.Stdout { log.Warn("stdout:", line) } for _, line := range result.Stderr { log.Warn("stderr:", line) } } else { log.Warn("THINGS FAILED ", repo.GetFullPath()) log.Warn("err", err) if result == nil { break } for _, line := range result.Stdout { log.Warn("stdout:", line) } for _, line := range result.Stderr { log.Warn("stderr:", line) } break } me.forge.SetConfigSave(true) // view.Update() } me.forge.ConfigSave() }