Browse Source

added interval and some minor refactoring

bmallred 10 years ago
parent
commit
3709699b5b
1 changed files with 27 additions and 12 deletions
  1. 27 12
      code-notify.go

+ 27 - 12
code-notify.go

11
	"regexp"
11
	"regexp"
12
	"runtime"
12
	"runtime"
13
	"strings"
13
	"strings"
14
	"time"
14
15
15
	"code.revolvingcow.com/revolvingcow/code/cmd"
16
	"code.revolvingcow.com/revolvingcow/code/cmd"
16
)
17
)
17
18
18
// Main entry point for the application.
19
// Main entry point for the application.
19
func main() {
20
func main() {
21
	// Configure any environment variables that may need to be applied
20
	cmd.ConfigureEnvironment()
22
	cmd.ConfigureEnvironment()
21
23
24
	// Find the root directory to start the hunt
22
	root := cmd.GetWorkingDirectory()
25
	root := cmd.GetWorkingDirectory()
23
	if len(os.Args[1:]) > 0 {
26
	if len(os.Args[1:]) > 0 {
24
		root = os.Args[1:][0]
27
		root = os.Args[1:][0]
25
	}
28
	}
26
	c := hunter(root)
27
29
28
	for m := range c {
29
		gatherer(m)
30
	// Loop through the repositories on an interval
31
	interval := 15 * time.Minute
32
	doEvery(interval, func() {
33
		c := hunter(root)
34
35
		for m := range c {
36
			gatherer(m)
37
		}
38
	})
39
}
40
41
// Repeat a piece of logic on an interval
42
func doEvery(d time.Duration, f func()) {
43
	log.Println("Execution scheduled every", d)
44
45
	for _ = range time.Tick(d) {
46
		log.Println("Scanning repositories for incoming changesets...")
47
		f()
30
	}
48
	}
31
}
49
}
32
50
81
99
82
	err := app.Run()
100
	err := app.Run()
83
	if err == nil {
101
	if err == nil {
84
		count := 0
85
		base := path.Base(directory)
102
		base := path.Base(directory)
86
		b := buffer.String()
103
		b := buffer.String()
87
104
88
		// Special logic to count the individual changesets
105
		// Special logic to count the individual changesets
106
		var re *regexp.Regexp
89
		switch {
107
		switch {
90
		case base == ".git":
108
		case base == ".git":
91
			re := regexp.MustCompile("commit")
92
			count = len(re.FindAllString(b, -1))
109
			re = regexp.MustCompile("commit")
93
			break
110
			break
94
		case base == ".hg":
111
		case base == ".hg":
95
			re := regexp.MustCompile("changeset")
96
			count = len(re.FindAllString(b, -1))
112
			re = regexp.MustCompile("changeset")
97
			break
113
			break
98
		case base == ".tf":
114
		case base == ".tf":
99
			re := regexp.MustCompile("revno")
100
			count = len(re.FindAllString(b, -1))
115
			re = regexp.MustCompile("revno")
101
			break
116
			break
102
		case base == ".bzr":
117
		case base == ".bzr":
103
			re := regexp.MustCompile("commit")
104
			count = len(re.FindAllString(b, -1))
118
			re = regexp.MustCompile("commit")
105
			break
119
			break
106
		}
120
		}
107
121
122
		count := len(re.FindAllString(b, -1))
108
		if count > 0 {
123
		if count > 0 {
109
			a := []string{}
124
			a := []string{}
110
125