summaryrefslogtreecommitdiff
path: root/scan.go
blob: 5945ecef908d1a11f038f12b9d79d0b70c1e6205 (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
package main

import (
	"fmt"
	"strings"
	"time"

	"go.wit.com/log"
)

func scanRepositories() {
	var i int = 0
	t := timeFunction(func() {
		for _, repo := range me.allrepos {
			repo.newScan()
			i += 1
		}
	})
	s := fmt.Sprint(t)
	log.Info("Scanned", i, "repositories. todo: count/show changes", 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)

	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.Checked() {
			r.Hide()
		}
		return true
	}
	return false
}

// 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()
		}
	}
}