// 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/gadgets" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func debug() { time.Sleep(2 * time.Second) for { now := time.Now() if me.repoAllB != nil { tmp := fmt.Sprintf("All (%d)", me.forge.Repos.Len()) me.repoAllB.SetLabel(tmp) } if me.repoDevelMergeB != nil { found := findMergeToDevel() tmp := fmt.Sprintf("needs merge to devel (%d)", found.Len()) me.repoDevelMergeB.SetLabel(tmp) } if me.repoWritableB != nil { found := gitpb.NewRepos() for repo := range me.forge.Repos.IterByFullPath() { 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() dirty := found.Len() if me.repoDirtyB != nil { tmp := fmt.Sprintf("dirty (%d)", dirty) me.repoDirtyB.SetLabel(tmp) } if me.reposWinB != nil { tmp := fmt.Sprintf("Repos (%d)", me.forge.Repos.Len()) if dirty > 0 { tmp = fmt.Sprintf("Repos (%d) (%d dirty)", me.forge.Repos.Len(), dirty) } me.reposWinB.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.NewGenericWindow("Forge: (this kinda works sometimes)", "Current Settings") 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.GenericWindow) { grid := win.Group.RawGrid() me.goSrcPwd = gadgets.NewOneLiner(grid, "Working Directory") grid.NewLabel("") 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) } grid.NextRow() // groupM := hbox.NewGroup("Windows") // gridM := groupM.RawGrid() // hbox := win.Stack.Box().Horizontal() gridM := win.Stack.RawGrid() var releaseWin *gadgets.GenericWindow gridM.NewButton("Release Window", func() { log.Info("todo: move releaser here") log.Info("for now, run guireleaser") if releaseWin != nil { releaseWin.Toggle() return } releaseWin = makeModeMasterWin() }) var patches *stdPatchsetTableWin gridM.NewButton("Patch Window", func() { if patches != nil { patches.Toggle() return } patches = makePatchsetsWin() }) var insertWin *gadgets.GenericWindow s := fmt.Sprintf("Repos (%d)", me.forge.Repos.Len()) me.reposWinB = gridM.NewButton(s, func() { // if the window exists, just toggle it open or closed if insertWin != nil { insertWin.Toggle() return } insertWin = makeReposWinNew() }) // var reposWin *gadgets.GenericWindow var reposWin *stdReposTableWin gridM.NewButton("Fix Repos", func() { if reposWin != nil { reposWin.Toggle() return } reposWin = makeReposWin() }) var patchesWin *stdPatchTableWin gridM.NewButton("Pending patches", func() { if patchesWin != nil { patchesWin.Toggle() return } loadUpstreamPatchsets() if me.psets == nil { log.Info("failed to download current patchsets") return } notdone := new(forgepb.Patches) all := me.psets.All() for all.Scan() { pset := all.Next() AddNotDonePatches(notdone, pset, false) } for patch := range notdone.IterAll() { comment := cleanSubject(patch.Comment) log.Info("new patch:", patch.NewHash, "commithash:", patch.CommitHash, patch.RepoNamespace, comment) } // savePatchsets() patchesWin = makePatchesWin(notdone) }) gridM.NextRow() var howtoWin *gadgets.GenericWindow gridM.NewButton("Tutorial", func() { if howtoWin != nil { howtoWin.Toggle() return } howtoWin = makeHowtoWin() }) gridM.NextRow() gridM.NewLabel("") } // this is the magic that generates a window directly from the protocol buffer func makeStandardReposGrid(pb *gitpb.Repos) *gitpb.ReposTable { t := pb.NewTable("testDirty") t.NewUuid() 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() for repo := range me.forge.Repos.IterByFullPath() { // this sees if user has patches for devel. If it does, add it to 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() *gitpb.Repos { 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 { found.AppendByGoPath(repo) } } now := time.Now() if found.Len() == 0 { log.Info("nothing to merge with master") return found } me.forge.PrintHumanTable(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))) return found } func mergeDevelToMaster(doit bool) { found := findMergeToMaster() if !doit { return } all := 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() }