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

import (
	"os"

	"go.wit.com/log"

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

// trys to figure out if there is still something to update
// todo: redo this logic as it is terrible
// rename this findNext()
func findNext() bool {
	loop := me.repos.View.ReposSortByName()
	for loop.Scan() {
		repo := loop.Repo()
		if repo.Status.IsReleased() {
			continue
		}
		if repo.Status.Whitelist {
			continue
		}
		if repo.ReadOnly() {
			// log.Info("findNext() skipping readonly")
			continue
		}
		if repo.CheckDirty() {
			log.Info("findNext() skipping dirty")
			continue
		}
		// do makeredomod here
		// if ! repo.Status.Exists("go.sum") {
		// }
		if repo.Status.IsPrimitive() {
			log.Info("findNext()", repo.GoPath())
			if setCurrentRepo(repo, "PRIMATIVE", "release new version") {
				return true
			}
			continue
		}
		log.Info("findNext()", repo.GoPath(), "is not a primative repo")
		check := me.forge.Repos.FindByGoPath(repo.GoPath())
		if check == nil {
			log.Info("boo, you didn't git clone", repo.GoPath())
			return false
		}
		if me.forge.FinalGoDepsCheck(check) {
			setCurrentRepo(repo, "should be good to release", "pretty sure")
			return true
		}
	}
	log.Info("tried to findNext() but not sure what to do next")
	me.release.status.SetText("ALL DONE?")
	return false
}

/*
func checkValidGoSum(repo *repolist.RepoRow) bool {
	if goodGodeps(repo) {
		log.Info("repo has go.sum requirements that are clean")
		// me.current.setGoSumStatus("CLEAN")
		me.release.status.SetValue("GOOD")
		me.release.notes.SetValue("CheckValidGoSum() does not seem to lie")
		return true
	}
	log.Info("go mod tidy not ok")
	me.release.notes.SetValue("CheckValidGoSum() failed")
	return false
}
*/

func goodGodeps(repo *repolist.RepoRow) bool {
	var good bool = true
	// check if the package dependancies changed, if so, re-publish
	check := me.forge.Repos.FindByGoPath(repo.GoPath())
	if check == nil {
		log.Info("boo, you didn't git clone", repo.GoPath())
		os.Exit(-1)
	}
	// check.RedoGoMod()
	log.Printf("current repo %s go dependancy count: %d", check.GetGoPath(), check.GoDepsLen())
	deps := check.GoDeps.SortByGoPath()
	for deps.Scan() {
		depRepo := deps.Next()
		// log.Info("found dep", depRepo.GetGoPath())
		if me.forge.IsReadOnly(depRepo.GetGoPath()) {
			// log.Info("IsReadOnly = true", depRepo.GetGoPath())
			continue
		} else {
			// log.Info("IsReadOnly = false", depRepo.GetGoPath())
		}
		found := me.repos.View.FindByPath(depRepo.GetGoPath())
		if found == nil {
			// log.Info("repos.View.FindByPath() not found", depRepo.GetGoPath())
			continue
		}
		if found.Status.IsReleased() {
			continue
		}
		header := found.StandardReleaseHeader()
		log.Info("bad", header)
		good = false
	}
	return good
}

// tries to fix the go.mod and go.sum files
func fixGodeps(repo *repolist.RepoRow) bool {
	var good bool = true
	// check if the package dependancies changed, if so, re-publish
	check := me.forge.Repos.FindByGoPath(repo.GoPath())
	if check == nil {
		log.Info("boo, you didn't git clone", repo.GoPath())
		os.Exit(-1)
	}
	check.RedoGoMod()
	log.Printf("current repo %s go dependancy count: %d", check.GetGoPath(), check.GoDepsLen())
	deps := check.GoDeps.SortByGoPath()
	for deps.Scan() {
		depRepo := deps.Next()
		// log.Info("found dep", depRepo.GetGoPath())
		if me.forge.IsReadOnly(depRepo.GetGoPath()) {
			log.Info("IsReadOnly = true", depRepo.GetGoPath())
			continue
		} else {
			// log.Info("IsReadOnly = false", depRepo.GetGoPath())
		}
		found := me.repos.View.FindByPath(depRepo.GetGoPath())
		if found == nil {
			log.Info("not found:", depRepo.GetGoPath())
			continue
		}
		if depRepo.GetVersion() != found.Status.GetMasterVersion() {
			log.Printf("%-48s  %10s (from gitpb)", depRepo.GetGoPath(), depRepo.GetVersion())
			header := found.StandardReleaseHeader()
			log.Info(header, "(from repolist)")
			cmd := []string{"go", "get", depRepo.GetGoPath() + "@latest"}
			check.Run(cmd)
		}
	}
	cmd := []string{"go", "mod", "tidy"}
	check.Run(cmd)
	cmd = []string{"go", "mod", "edit", "-go=1.20"}
	check.Run(cmd)
	check.GoDeps = nil
	check.ParseGoSum()

	deps = check.GoDeps.SortByGoPath()
	for deps.Scan() {
		depRepo := deps.Next()
		log.Info("found updated dep", depRepo.GetGoPath(), depRepo.GetVersion())
	}
	return good
}