summaryrefslogtreecommitdiff
path: root/scan.go
blob: e68747fbd1180eb68cbcea6e5a9f679730df21b4 (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
package repolist

import (
	"fmt"
	"strconv"

	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

func (r *RepoList) RegisterHideFunction(f func(*RepoRow)) {
	me.hideFunction = f
}

func (r *RepoList) ScanRepositories() (int, string) {
	var i int
	var shown int
	var total int
	t := TimeFunction(func() {
		for _, repo := range me.allrepos {
			i += 1
			changed := repo.NewScan()
			total += changed
		}
		var hidden int
		for _, repo := range me.allrepos {
			if repo.Hidden() {
				hidden += 1
			} else {
				shown += 1
			}
		}
	})
	s := fmt.Sprint(t)
	tmp := strconv.Itoa(shown) + " repos shown"
	me.shownCount.SetText(tmp)
	me.duration.SetText(s)

	log.Info("repolist Scanned", i, "repositories.", total, "changes in", s)
	return i, s
}

func (r *RepoRow) UpdatePb(newpb *gitpb.Repo) {
	r.pb = newpb
}

func (r *RepoRow) NewScan() int {
	var changed int = 0
	if r.Status == nil {
		log.Log(WARN, "repo.Status = nil. not initialized for some reason")
		return changed
	}
	pb := r.pb
	if pb == nil {
		log.Log(WARN, "NewScan() pb = nil")
		return changed
	}

	if r.lastTag != nil {
		r.lastTag.SetLabel(pb.GetLastTag())
	}

	// run the repostatus update
	r.Status.Update()

	r.masterVersion.SetLabel(pb.GetMasterVersion())
	r.develVersion.SetLabel(pb.GetDevelVersion())
	r.userVersion.SetLabel(pb.GetUserVersion())
	r.gitState.SetLabel(r.Status.CheckGitState())
	r.pbState.SetLabel(pb.GetState())
	r.currentName.SetLabel(pb.GetCurrentBranchName())
	r.currentVersion.SetLabel(pb.GetCurrentBranchVersion())

	if r.State() == "merge to main" {
		r.Hide()
	}
	if r.Status.GitState() == "PERFECT" {
		r.Hide()
	} else {
		r.Show()
	}

	return changed
}