summaryrefslogtreecommitdiff
path: root/scan.go
blob: f60f73a54bffe15bf1be31ee13e1b5ee3174d6eb (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
// This is a simple example
package main

import (
	"fmt"
	"time"

	"go.wit.com/log"

	"go.wit.com/lib/gui/repostatus"
)

func (r *repo) newScan() bool {
	if r.status == nil {
		log.Warn("repo.status = nil. not initialized for some reason")
		return false
	}
	// r.scan()
	if repostatus.VerifyLocalGoRepo(r.getPath()) {
		log.Verbose("repo actually exists", r.getPath())
	} else {
		log.Warn("repo does not exist", r.getPath())
		return false
	}
	mname := r.status.GetMasterBranchName()
	mver := r.status.GetMasterVersion()
	if mname != "guimaster" {
		mver = mver + " (" + mname + ")"
	}
	r.masterVersion.SetLabel(mver)

	dname := r.status.GetDevelBranchName()
	dver := r.status.GetDevelVersion()
	if dname != "devel" {
		dver = dver + " (" + dname + ")"
	}
	r.develVersion.SetLabel(dver)

	uname := r.status.GetUserBranchName()
	uver := r.status.GetUserVersion()
	if uname != "jcarr" {
		uver = uver + " (" + uname + ")"
	}
	r.userVersion.SetLabel(uver)

	cbname := r.status.GetCurrentBranchName()
	cbversion := r.status.GetCurrentBranchVersion()
	lasttag := r.status.GetLastTagVersion()
	r.lastTag.SetLabel(lasttag)
	r.vLabel.SetLabel(cbname + " " + cbversion)

	if r.status.Changed() {
		log.Warn("should scan here")
	}
	status := r.status.GetStatus()
	r.dirtyLabel.SetLabel(status)
	if status == "PERFECT" {
		if me.autoHidePerfect.Checked() {
			r.Hide()
		}
		return true
	}
	return false
}

func (r *repo) getStatus() string {
	if r.status.CheckDirty() {
		log.Warn("CheckDirty() true")
		return "dirty"
	}

	if r.status.CheckBranches() {
		log.Warn("Branches are Perfect")
		return "PERFECT"
	}
	log.Warn("Branches are not Perfect")
	return "merge"
}

func (r *repo) getGoSumStatus() string {
	return r.goSumStatus.String()
}

func (r *repo) setGoSumStatus(s string) {
	r.goSumStatus.SetLabel(s)
	r.status.SetGoSumStatus(s)
}

func scanGoSum() {
	for _, repo := range me.allrepos {
		latestversion := repo.status.GetLastTagVersion()
		if repo.getGoSumStatus() == "BAD" {
			continue
		}
		if repo.getGoSumStatus() == "DIRTY" {
			continue
		}
		if repo.status.CheckPrimativeGoMod() {
			log.Info("PRIMATIVE repo:", latestversion, repo.status.String())
			repo.setGoSumStatus("PRIMATIVE")
			continue
		}
		if repo.status.CheckDirty() {
			log.Info("dirty repo:", latestversion, repo.status.String())
			log.Info("dirty repo.getGoSumStatus =", repo.getGoSumStatus())
			repo.setGoSumStatus("DIRTY")

			// release.repo.SetValue(repo.status.String())
			// release.status.SetValue("dirty")
			// release.notes.SetValue("You must commit your changes\nbefore you can continue")
			// release.current = repo
			// release.openrepo.Enable()
			continue
		}
		if ok, missing := repo.status.CheckGoSum(); ok {
			log.Info("repo has go.sum requirements that are clean")
			repo.setGoSumStatus("CLEAN")
		} else {
			log.Info("repo has go.sum requirements that are screwed up. missing:", missing)
			repo.setGoSumStatus("BAD")

			// release.repo.SetValue(repo.status.String())
			// release.status.SetValue("bad")
			// release.notes.SetValue("the go.sum file is wrong")
			// release.current = repo
			// release.openrepo.Enable()
			continue
		}
		status := repo.dirtyLabel.String()
		if status == "PERFECT" {
			continue
		} else {
			repo.status.Update()
			repo.newScan()
		}

		// log.Info("find the next repo to release here")
		log.Info("repo:", latestversion, status, repo.status.String())
	}
	log.Info("scan() did everything, not sure what to do next")
}

// timeFunction takes a function as an argument and returns the execution time.
func timeFunction(f func()) time.Duration {
	startTime := time.Now()      // Record the start time
	f()                          // Execute the function
	return time.Since(startTime) // Calculate the elapsed time
}

func myTicker(t time.Duration, name string, f func()) {
	ticker := time.NewTicker(t)
	defer ticker.Stop()
	done := make(chan bool)
	/*
		go func() {
			time.Sleep(10 * time.Second)
			done <- true
		}()
	*/
	for {
		select {
		case <-done:
			fmt.Println("Done!")
			return
		case t := <-ticker.C:
			log.Verbose(name, "Current time: ", t)
			f()
		}
	}
}