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

import (
	"fmt"
	"strconv"
	"strings"

	"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) NewScan() int {
	return r.NewScan2(r.pb)
}

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

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

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

	if r.masterVersion == nil {
		panic("what the fuck node")
	}
	if r.pb == nil {
		panic("what the fuck pb")
	}
	r.masterVersion.SetLabel(pb.GetMasterVersion())
	r.develVersion.SetLabel(pb.GetDevelVersion())
	r.userVersion.SetLabel(pb.GetUserVersion())
	r.gitState.SetLabel(r.Status.GitState())
	r.currentName.SetLabel(r.Status.GetCurrentBranchName())
	r.currentVersion.SetLabel(r.Status.GetCurrentBranchVersion())

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

	/*
		tags := []string{"%(objectname)", "%(creatordate)", "%(*authordate)", "%(refname)", "%(subject)"}
		format := strings.Join(tags, "_,,,_")
		cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format}
		// log.Info("RUNNING:", strings.Join(cmd, " "))
		result := r.pb.RunQuiet(cmd)
		if result.Error != nil {
			log.Warn("git for-each-ref error:", result.Error)
		}
		for i, line := range result.Stdout {
			log.Info(i, line)
		}

		if me.hideFunction == nil {
			// application didn't register a hide function
			// always show everything in that case
			r.Show()
		} else {
			me.hideFunction(r)
		}
	*/

	// print out whatever changes have happened
	if c, ok := r.Status.Changed(); ok {
		log.Log(REPOWARN, "something finally changed")
		c := strings.TrimSpace(c)
		for _, line := range strings.Split(c, "\n") {
			log.Log(REPOWARN, r.Status.Path(), line)
			changed += 1
		}
	}

	return changed
}