forge/windowPatches.go

164 lines
3.8 KiB
Go
Raw Normal View History

package main
import (
2025-01-06 19:03:35 -06:00
"fmt"
"strconv"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/log"
)
type patchSummary struct {
2025-01-06 19:03:35 -06:00
grid *gui.Node
updateB *gui.Node
docsB *gui.Node
gitPushB *gui.Node
gitPullB *gui.Node
checkB *gui.Node
totalOL *gadgets.OneLiner
2024-02-18 07:24:56 -06:00
dirtyOL *gadgets.OneLiner
readonlyOL *gadgets.OneLiner
2025-01-06 19:03:35 -06:00
rw *gadgets.OneLiner
2024-02-18 07:24:56 -06:00
totalPatchesOL *gadgets.OneLiner
totalUserRepos *gui.Node
totalDevelRepos *gui.Node
totalMasterRepos *gui.Node
totalUserPatches *gui.Node
totalDevelPatches *gui.Node
totalMasterPatches *gui.Node
2025-01-06 19:03:35 -06:00
fileCount *gui.Node
unknownOL *gadgets.BasicEntry
unknownSubmitB *gui.Node
reason *gadgets.BasicEntry
submitB *gui.Node
2025-01-07 18:06:29 -06:00
// allp []*repolist.Patch
}
func submitPatchesBox(box *gui.Node) *patchSummary {
s := new(patchSummary)
group1 := box.NewGroup("Patch Summary")
s.grid = group1.RawGrid()
s.totalOL = gadgets.NewOneLiner(s.grid, "Total")
2025-01-06 19:03:35 -06:00
_ = s.grid.NewLabel("total changes")
_ = s.grid.NewLabel("user to devel")
s.grid.NextRow()
s.dirtyOL = gadgets.NewOneLiner(s.grid, "dirty")
2025-01-06 19:03:35 -06:00
_ = s.grid.NewLabel("") // skip a column
2024-02-20 10:58:58 -06:00
s.totalUserRepos = s.grid.NewLabel("x go repos")
s.grid.NextRow()
2025-01-06 19:03:35 -06:00
s.readonlyOL = gadgets.NewOneLiner(s.grid, "read-only")
_ = s.grid.NewLabel("") // skip a column
2024-02-20 10:58:58 -06:00
s.totalUserPatches = s.grid.NewLabel("x patches")
2024-02-18 07:24:56 -06:00
s.grid.NextRow()
2025-01-06 19:03:35 -06:00
s.rw = gadgets.NewOneLiner(s.grid, "r/w")
_ = s.grid.NewLabel("") // skip a column
s.fileCount = s.grid.NewLabel("x files")
s.grid.NextRow()
group1 = box.NewGroup("Submit Patch Set")
2024-02-18 07:24:56 -06:00
s.grid = group1.RawGrid()
s.reason = gadgets.NewBasicEntry(s.grid, "set name:")
s.reason.Custom = func() {
if s.reason.String() != "" {
s.submitB.Enable()
} else {
s.submitB.Disable()
}
}
s.submitB = s.grid.NewButton("Submit", func() {
2024-12-29 21:36:39 -06:00
if err := sendDevelDiff(s.reason.String()); err != nil {
log.Info("sending patches failed", err)
} else {
log.Info("sent patch set ok")
}
})
2025-01-05 02:01:15 -06:00
2025-01-05 04:54:05 -06:00
s.grid.NewButton("List Patchsets", func() {
2024-12-23 11:15:16 -06:00
listPatches()
})
2025-01-05 02:01:15 -06:00
2025-01-05 04:54:05 -06:00
s.grid.NewButton("Show Latest Patchset", func() {
2025-01-05 02:01:15 -06:00
lastp := lastPatch()
pset, err := getPatch(lastp)
if err != nil {
return
}
2025-01-05 04:54:05 -06:00
if !dumpPatchset(pset) {
log.Info("some patches are bad")
return
}
if IsAnythingDirty() {
log.Info("You can't apply patches when repos are dirty")
me.forge.PrintHumanTable(me.found)
2025-01-05 04:54:05 -06:00
return
}
})
s.grid.NewButton("Apply Latest Patchset", func() {
lastp := lastPatch()
pset, err := getPatch(lastp)
if err != nil {
return
}
if !IsEverythingOnDevel() {
log.Info("You can only apply patches to the devel branch")
return
}
2025-01-05 04:54:05 -06:00
if IsAnythingDirty() {
log.Info("You can't apply patches when repos are dirty")
me.forge.PrintHumanTable(me.found)
2025-01-05 04:54:05 -06:00
return
}
applyPatchset(pset)
2025-01-05 02:01:15 -06:00
})
2024-12-23 03:27:29 -06:00
s.grid.NewButton("Show Repos", func() {
s.Update()
if me.repos.Hidden() {
me.repos.Show()
} else {
me.repos.Hide()
}
})
// disable these until there are not dirty repos
// s.reason.Disable()
s.submitB.Disable()
2024-02-20 10:58:58 -06:00
s.grid.NextRow()
return s
}
2024-02-20 10:58:58 -06:00
// does not run any commands
func (s *patchSummary) Update() {
2025-01-06 19:03:35 -06:00
var total, dirty, readonly, rw int
var userT int // , develT, masterT int
2024-02-18 07:24:56 -06:00
// var userP, develP, masterP int
2024-12-02 15:45:06 -06:00
// broken after move to forge protobuf
2024-12-17 06:36:00 -06:00
all := me.forge.Repos.SortByFullPath()
2024-12-11 19:32:04 -06:00
for all.Scan() {
repo := all.Next()
total += 1
2024-12-02 15:45:06 -06:00
if repo.IsDirty() {
2024-02-20 10:58:58 -06:00
dirty += 1
}
2025-01-06 19:03:35 -06:00
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
readonly += 1
2025-01-06 19:03:35 -06:00
} else {
rw += 1
2024-02-18 07:24:56 -06:00
}
}
s.totalOL.SetText(strconv.Itoa(total) + " repos")
s.dirtyOL.SetText(strconv.Itoa(dirty) + " repos")
s.readonlyOL.SetText(strconv.Itoa(readonly) + " repos")
2025-01-06 19:03:35 -06:00
s.rw.SetText(fmt.Sprintf("%d repos", rw))
2024-02-18 07:24:56 -06:00
s.totalUserRepos.SetText(strconv.Itoa(userT) + " repos")
}