-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (34 loc) · 1.05 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
package main
import (
"gogitponas/gitlab"
"gogitponas/registry"
"gogitponas/rocketchat"
"gogitponas/slack"
"log"
"os"
"strconv"
"strings"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
gitlabURL := os.Getenv("GITLAB_URL")
gitlabToken := os.Getenv("GITLAB_TOKEN")
gitlabProjects := strings.Split(os.Getenv("GITLAB_PROJECTS"), ",")
g := gitlab.New(gitlabToken, gitlabURL)
notificationTargets := registry.New(strings.Split(os.Getenv("NOTIFICATION_TARGETS"), ","))
notificationTargets.Register("slack", &Slack{sc: slack.New(os.Getenv("SLACK_HOOK"), slack.NewClient())})
notificationTargets.Register("rocket", &Rocket{rc: rocketchat.New(os.Getenv("ROCKET_HOOK"), rocketchat.NewClient())})
oldAgeDays, err := strconv.Atoi(os.Getenv("MR_OLD_AGE_DAYS"))
if err != nil {
log.Fatalf("Cannot convert days string to integer")
}
for _, project := range gitlabProjects {
for _, mr := range g.GetOldMergeRequests(project, oldAgeDays) {
notificationTargets.Send(mr)
}
}
}