-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (81 loc) · 2.13 KB
/
main.go
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
package main
import (
"flag"
jenkins "github.com/bndr/gojenkins"
"github.com/davecheney/gpio"
"github.com/shilkin/buildstatus/dispatcher"
"github.com/shilkin/buildstatus/status"
"github.com/shilkin/buildstatus/view"
"log"
"strings"
"time"
)
var (
// jenkins options
url string
login string
pass string
projects string
timeout time.Duration
// pin numbers
yellow int
red int
green int
// common
rendertype string
)
func init() {
const (
defUrl = "http://localhost"
defLogin = "shilkin"
defPass = "qwerty12345"
defProjects = "Acceptance tests, Local projects"
defYellow = gpio.GPIO10
defRed = gpio.GPIO9
defGreen = gpio.GPIO11
defTimeout = 500 * time.Millisecond
defRender = "stdout"
)
flag.StringVar(&url, "url", defUrl, "jenkins url 'http://jenkinsurl<:port>'")
flag.StringVar(&login, "login", defLogin, "jenkins login")
flag.StringVar(&pass, "pass", defPass, "jenkins pass")
flag.StringVar(&projects, "projects", defProjects, "comma-separated list of projects")
flag.DurationVar(&timeout, "timeout", defTimeout, "jenkins read timeout")
flag.IntVar(&yellow, "ypin", defYellow, "yellow pin number")
flag.IntVar(&red, "rpin", defRed, "red pin number")
flag.IntVar(&green, "gpin", defGreen, "green pin number")
flag.StringVar(&rendertype, "render", defRender, "render type (trafficlight, stdout)")
}
func main() {
flag.Parse()
client, err := jenkins.CreateJenkins(url, login, pass).Init()
if err != nil {
log.Fatal(err)
}
projectsList := strings.Split(projects, ",")
if len(projectsList) == 1 && projectsList[0] == "" {
projectsList = []string{}
}
log.Printf("watching projects: %#v", projectsList)
reader := status.NewReader(client,
status.ReaderOpts{
TimeoutRead: timeout,
Views: projectsList,
})
var render view.Render
switch rendertype {
case "stdout":
render = view.NewStdoutRender()
case "trafficlight":
render, err = view.NewRaspberryRender(view.RaspberryOpts{
GpioYellow: yellow,
GpioRed: red,
GpioGreen: green,
})
if err != nil {
log.Fatal(err)
}
}
disp := dispatcher.NewDispatcher(reader, render)
disp.Run()
}