-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (37 loc) · 948 Bytes
/
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
// Post build status results to Slack.
package main
import (
"context"
"flag"
"log"
"./slackbot"
)
var (
build = flag.String("build", "", "Build ID being monitored")
webhook = flag.String("webhook", "", "Slack webhook URL")
mode = flag.String("mode", "trigger", "Mode the builder runs in")
)
func main() {
log.Print("Starting slackbot")
flag.Parse()
ctx := context.Background()
if *webhook == "" {
log.Fatalf("Slack webhook must be provided.")
}
if *build == "" {
log.Fatalf("Build ID must be provided.")
}
if *mode == "trigger" {
// Trigger another build to run the monitor.
log.Printf("Starting trigger mode for build %s", *build)
slackbot.Trigger(ctx, *build, *webhook)
return
}
if *mode == "monitor" {
// Monitor the other build until completion.
log.Printf("Starting monitor mode for build %s", *build)
slackbot.Monitor(ctx, *build, *webhook)
return
}
log.Fatalf("Mode must be provided.")
}