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

import (
	"fmt"
	"os/user"
	"strings"

	"go.wit.com/log"
)

func (r *RepoList) SetAutoScan(b bool) {
	me.autoScan = b
}

func (r *RepoList) ScanRepositories() (int, string) {
	var i int
	t := timeFunction(func() {
		for _, repo := range me.allrepos {
			i += 1
			repo.NewScan()
		}
	})
	s := fmt.Sprint(t)
	log.Info("Scanned", i, "repositories. todo: count/show changes", s)
	return i, s
}

func (r *Repo) NewScan() bool {
	if r.Status == nil {
		log.Warn("repo.Status = nil. not initialized for some reason")
		return false
	}

	// first run the repostatus update
	r.Status.UpdateNew()

	// now read those values and display them in our table
	mname := r.Status.GetMasterBranchName()
	mver := r.Status.GetMasterVersion()
	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()
	usr, _ := user.Current()
	if uname != usr.Username {
		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 c, ok := r.Status.Changed(); ok {
		c := strings.TrimSpace(c)
		for _, line := range strings.Split(c, "\n") {
			log.Info(r.Status.Path(), line)
		}
	}
	status := r.Status.GetStatus()
	r.dirtyLabel.SetLabel(status)
	if status == "PERFECT" {
		if me.autoHidePerfect {
			r.Hide()
		}
		return true
	}
	return false
}