-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (48 loc) · 1.08 KB
/
main.go
File metadata and controls
53 lines (48 loc) · 1.08 KB
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
package main
import (
"fmt"
"github.com/slack-go/slack"
"hooker/bot"
"hooker/command"
"hooker/config"
"hooker/git"
"log"
"reflect"
)
var configs []*config.ProjectConfig
func main() {
var err error
configs, err = config.LoadConfig("config.yaml")
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}
for _, conf := range configs {
conf.Queue = make(chan interface{}, 100)
if conf.HasBot() {
conf.Bot = bot.NewSlackBot(
conf.SlackAuthToken,
conf.SlackAuthUserToken,
conf.SlackChannelID,
conf.BotName,
conf.Queue,
)
}
go startQueueHandler(conf.Queue, conf)
}
git.StartRestApiServer(configs)
}
func startQueueHandler(queue chan interface{}, config *config.ProjectConfig) {
for message := range queue {
switch castedMessage := message.(type) {
case git.Body:
git.ProcessGitHookBody(castedMessage, config)
case slack.Message:
// User message
if castedMessage.BotID == "" {
command.HandleCommand(castedMessage.Text, config)
}
default:
fmt.Printf("Received a non-Body message: %v\n", reflect.TypeOf(message))
}
}
}