summaryrefslogtreecommitdiff
path: root/submitPatches.go
blob: e3d4d97db690a432f2f876c4f17f7278b4578649 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package main

import (
	"path/filepath"
	"strconv"

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

/*
type patch struct {
	ref     string
	giturl  string
	comment string
	rs      *repostatus.RepoStatus
}
*/

type patchSummary struct {
	grid     *gui.Node
	updateB  *gui.Node
	docsB    *gui.Node
	gitPushB *gui.Node
	gitPullB *gui.Node
	checkB   *gui.Node

	// stats
	totalOL            *gadgets.OneLiner
	totalGoOL          *gadgets.OneLiner
	dirtyOL            *gadgets.OneLiner
	readonlyOL         *gadgets.OneLiner
	totalPatchesOL     *gadgets.OneLiner
	totalUserRepos     *gui.Node
	totalDevelRepos    *gui.Node
	totalMasterRepos   *gui.Node
	totalUserPatches   *gui.Node
	totalDevelPatches  *gui.Node
	totalMasterPatches *gui.Node

	// patch set generation
	unknownOL      *gadgets.OneLiner
	unknownSubmitB *gui.Node
	reason         *gadgets.BasicEntry
	submitB        *gui.Node
	allp           []*repolist.Patch
}

func submitPatchesBox(box *gui.Node) *patchSummary {
	s := new(patchSummary)
	group1 := box.NewGroup("Submit Patches Summary")
	s.grid = group1.RawGrid()

	s.grid.NewButton("List Patches", func() {
		for i, p := range s.allp {
			log.Info(i, p.Ref, p.RS.String())
		}
		// update the stats
		s.Update()
	})

	s.grid.NewButton("GetPatches()", func() {
		var repocount, count int
		for _, repo := range repolist.AllRepos() {
		//	if repo.GoPath() == "go.wit.com/apps/guireleaser" {
				// repo.GetUserPatches()
				if repo.ReadOnly() {
					continue
				}
				//if repo.IsDirty() {
				//	continue
				//}
				patchc, _ := repo.GetMasterPatches()
				count += patchc
				repocount += 1
		//	}
		}
		s.totalMasterPatches.SetText(strconv.Itoa(count) + " patches")
		s.totalMasterRepos.SetText(strconv.Itoa(repocount) + " go repos")
	})

	s.gitPullB = s.grid.NewButton("git pull", func() {
		me.Disable()
		defer me.Enable()
		for _, repo := range repolist.AllRepos() {
			// gitcmd := []string{"git", "fetch", "origin"}
			gitcmd := []string{"git", "pull"}
			err, output := repo.RunCmd(gitcmd)
			log.Info("output =", output)
			if err == nil {
				log.Info("git fetch worked", repo.Name())
			} else {
				log.Info("git fetch failed", repo.Name())
				return
			}
		}
		s.gitPullB.SetText("GOOD")
		// update the stats
		s.Update()
	})

	s.gitPushB = s.grid.NewButton("git push", func() {
		me.Disable()
		defer me.Enable()
		for _, repo := range repolist.AllRepos() {
			gitcmd := []string{"git", "push"}
			err, output := repo.RunCmd(gitcmd)
			log.Info("output =", output)
			if err == nil {
				log.Info("git push worked", repo.Name())
			} else {
				log.Info("git push failed", repo.Name())
				return
			}
		}
		s.gitPushB.SetText("GOOD")
		// update the stats
		s.Update()
	})

	s.checkB = s.grid.NewButton("Check repos are working", func() {
		/*
			me.Disable()
			defer me.Enable()
			for _, repo := range repolist.AllRepos() {
				if repo.GitURL() != "" {
					log.Info("repo already checked. do they match?")
					log.Info("go.wit.com =", repo.GoURL())
					log.Info("localurl   =", repo.Path())
				} else {
					ok, giturl := gowit.CheckRegistered(repo)
					if ok {
						log.Info("is url correct?", repo.Path(), "vs", giturl)
						repo.giturl = giturl
						if giturl != repo.Path() {
							log.Info("repo check failed", repo.String())
							s.unknownOL.SetText(repo.String())
							s.unknownOL.Show()
							s.unknownSubmitB.Show()
							return
						}
					} else {
						log.Info("repo check failed", repo.String())
						repo.giturl = "look in .git/config"
						s.unknownOL.SetText(repo.String())
						s.unknownOL.Show()
						s.unknownSubmitB.Show()
						return
					}
				}
			}
			s.checkB.SetText("GOOD")
		*/
	})
	s.grid.NextRow()

	s.unknownOL = gadgets.NewOneLiner(s.grid, "Unknown Repo:")
	s.unknownSubmitB = s.grid.NewButton("Register Repo", func() {
		/*
			log.Info("Submit repo:", s.unknownOL.String())
			if repolist.Exists(s.unknownOL.String()) {
				log.Info("found repo:", repo.String(), "with giturl", repo.giturl)
				localurl := repo.status.GitURL()
				if localurl == "" {
					log.Info("local repo check failed. repo is not uploaded?")
				} else {
					log.Info("local repo has", localurl)
					// attempts to register the unknown repo
					if gowit.Register(repo.String(), localurl) {
						s.unknownOL.Hide()
						s.unknownSubmitB.Hide()
					}
				}
			} else {
				log.Info("what is this?", s.unknownOL.String())
			}
		*/
	})
	s.unknownOL.Hide()
	s.unknownSubmitB.Hide()
	s.grid.NextRow()

	s.grid = group1.RawGrid()
	s.grid.NewLabel("")
	s.grid.NewLabel("")
	s.grid.NewLabel("user to devel")
	s.grid.NewLabel("devel to master")
	s.grid.NewLabel("master to last tag")
	s.grid.NextRow()

	s.totalOL = gadgets.NewOneLiner(s.grid, "Total")
	s.grid.NextRow()

	s.totalGoOL = gadgets.NewOneLiner(s.grid, "Total GO")
	s.totalUserRepos = s.grid.NewLabel("5 go repos")
	s.totalDevelRepos = s.grid.NewLabel("3 go repos")
	s.totalMasterRepos = s.grid.NewLabel("8 go repos")
	s.grid.NextRow()

	s.dirtyOL = gadgets.NewOneLiner(s.grid, "dirty")
	s.grid.NextRow()

	s.readonlyOL = gadgets.NewOneLiner(s.grid, "read-only")
	s.grid.NextRow()

	s.totalPatchesOL = gadgets.NewOneLiner(s.grid, "total commits")
	s.totalUserPatches = s.grid.NewLabel("5 patches")
	s.totalDevelPatches = s.grid.NewLabel("3 patches")
	s.totalMasterPatches = s.grid.NewLabel("8 patches")
	s.grid.NextRow()

	s.grid.NewLabel("")
	s.grid.NewLabel("")
	s.grid.NewButton("merge from user", func() {})
	s.grid.NewButton("merge from devel", func() {})
	s.grid.NextRow()

	group1 = box.NewGroup("Create GUI Patch Set")
	s.grid = group1.RawGrid()
	s.reason = gadgets.NewBasicEntry(s.grid, "patch name:")
	s.reason.Custom = func() {
		if s.reason.String() != "" {
			s.submitB.Enable()
		} else {
			s.submitB.Disable()
		}
	}
	s.submitB = s.grid.NewButton("Submit Patches", func() {
		patchdir := filepath.Join(me.userHomePwd.String(), "autotypist.patchset")
		if shell.Exists(patchdir) {
			log.Info("patchset dir already exists", patchdir)
			return
		} else {
			shell.Mkdir(patchdir)
		}
		if !shell.Exists(patchdir) {
			log.Info("something went wrong making", patchdir)
			return
		}
	})
	// disable these until there are not dirty repos
	s.reason.Disable()
	s.submitB.Disable()

	return s
}

func (s *patchSummary) Update() {
	var total, totalgo, dirty, readonly int
	var userT, develT, masterT int
	// var userP, develP, masterP int
	for _, repo := range repolist.AllRepos() {
		total += 1
		if repo.Status.IsDirty() {
			if repo.Status.GoPath() == "go.wit.com/apps/autotypist" {
				// log.Info("ignoring dirty autotypist for now")
				dirty += 1
			} else {
				dirty += 1
			}
		}
		if repo.Status.ReadOnly() {
			readonly += 1
		}
		if repo.Status.IsGoLang() {
			totalgo += 1
		}
		userV := repo.Status.GetUserVersion()
		develV := repo.Status.GetDevelVersion()
		masterV := repo.Status.GetMasterVersion()
		lastV := repo.Status.GetLastTagVersion()
		if userV != develV {
			userT += 1
		}
		if develV != masterV {
			develT += 1
		}
		if masterV != lastV {
			masterT += 1
		}
	}
	s.totalOL.SetText(strconv.Itoa(total) + " repos")
	s.totalGoOL.SetText(strconv.Itoa(totalgo) + " repos")
	s.dirtyOL.SetText(strconv.Itoa(dirty) + " repos")
	s.readonlyOL.SetText(strconv.Itoa(readonly) + " repos")

	s.totalUserRepos.SetText(strconv.Itoa(userT) + " repos")
	s.totalDevelRepos.SetText(strconv.Itoa(develT) + " repos")
	s.totalMasterRepos.SetText(strconv.Itoa(masterT) + " repos")
}