-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (53 loc) · 1.12 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
package main
import (
"context"
"log"
"os"
"strconv"
"time"
"github.com/google/go-github/v35/github"
"golang.org/x/oauth2"
)
const (
Nick = "build-bot"
Chan = "#dashboard"
)
var (
Username = os.Getenv("SASL_USER")
Password = os.Getenv("SASL_PASSWORD")
Server = os.Getenv("SERVER")
VerifyTLS = os.Getenv("VERIFY_TLS") == "true"
GithubToken = os.Getenv("GITHUB_TOKEN")
PollPeriod = os.Getenv("POLL_PERIOD")
)
func must(i interface{}, err error) interface{} {
if err != nil {
panic(err)
}
return i
}
func githubClient(token string) *github.Client {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(context.Background(), ts)
return github.NewClient(tc)
}
func main() {
seconds, err := strconv.Atoi(PollPeriod)
if err != nil {
panic(err)
}
c, err := New(Username, Password, Server, VerifyTLS, githubClient(GithubToken))
if err != nil {
panic(err)
}
go c.bottom.Client.Connect()
ticker := time.NewTicker(time.Second * time.Duration(seconds))
for range ticker.C {
err = c.processNotifications()
if err != nil {
log.Print(err)
}
}
}