summaryrefslogtreecommitdiff
path: root/windowPatches.go
blob: 916ab66a1793622861f3a16698f372541dee6dbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main

import (
	"fmt"
	"strconv"

	"go.wit.com/gui"
	"go.wit.com/lib/gadgets"
	"go.wit.com/log"
)

type patchSummary struct {
	grid               *gui.Node
	updateB            *gui.Node
	docsB              *gui.Node
	gitPushB           *gui.Node
	gitPullB           *gui.Node
	checkB             *gui.Node
	totalOL            *gadgets.OneLiner
	dirtyOL            *gadgets.OneLiner
	readonlyOL         *gadgets.OneLiner
	rw                 *gadgets.OneLiner
	totalPatchesOL     *gadgets.OneLiner
	totalUserRepos     *gui.Node
	totalDevelRepos    *gui.Node
	totalMasterRepos   *gui.Node
	totalUserPatches   *gui.Node
	totalDevelPatches  *gui.Node
	totalMasterPatches *gui.Node
	fileCount          *gui.Node
	unknownOL          *gadgets.BasicEntry
	unknownSubmitB     *gui.Node
	reason             *gadgets.BasicEntry
	submitB            *gui.Node
	// 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")
	_ = s.grid.NewLabel("total changes")
	_ = s.grid.NewLabel("user to devel")
	s.grid.NextRow()

	s.dirtyOL = gadgets.NewOneLiner(s.grid, "dirty")
	_ = s.grid.NewLabel("") // skip a column
	s.totalUserRepos = s.grid.NewLabel("x go repos")
	s.grid.NextRow()

	s.readonlyOL = gadgets.NewOneLiner(s.grid, "read-only")
	_ = s.grid.NewLabel("") // skip a column
	s.totalUserPatches = s.grid.NewLabel("x patches")
	s.grid.NextRow()

	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")
	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() {
		doSubmit(s.reason.String())
	})

	s.grid.NewButton("List Patchsets", func() {
		if err := listPatches(); err != nil {
			log.Info(err)
		}
	})

	s.grid.NewButton("Show Latest Patchset", func() {
		lastp := lastPatch()
		pset, err := getPatch(lastp)
		if err != nil {
			return
		}

		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)
			return
		}
	})

	s.grid.NewButton("Apply Latest Patchset", func() {
		lastp := lastPatch()
		pset, err := getPatch(lastp)
		if err != nil {
			return
		}
		if err := IsEverythingOnDevel(); err != nil {
			log.Info("You can only apply patches to the devel branch")
			return
		}
		if IsAnythingDirty() {
			log.Info("You can't apply patches when repos are dirty")
			me.forge.PrintHumanTable(me.found)
			return
		}
		applyPatchset(pset)
	})

	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()
	s.grid.NextRow()

	return s
}

// does not run any commands
func (s *patchSummary) Update() {
	var total, dirty, readonly, rw int
	var userT int // , develT, masterT int
	// var userP, develP, masterP int
	// broken after move to forge protobuf
	all := me.forge.Repos.SortByFullPath()
	for all.Scan() {
		repo := all.Next()
		total += 1
		if repo.IsDirty() {
			dirty += 1
		}
		if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
			readonly += 1
		} else {
			rw += 1
		}
	}
	s.totalOL.SetText(strconv.Itoa(total) + " repos")
	s.dirtyOL.SetText(strconv.Itoa(dirty) + " repos")
	s.readonlyOL.SetText(strconv.Itoa(readonly) + " repos")
	s.rw.SetText(fmt.Sprintf("%d repos", rw))

	s.totalUserRepos.SetText(strconv.Itoa(userT) + " repos")
}