forked from justwatchcom/github-releases-notifier
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
71 lines (60 loc) · 1.68 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
package main
import (
"github.com/alexflint/go-arg"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/joho/godotenv"
models2 "github.com/magmel48/github-releases-notifier/pkg/models"
"os"
"strings"
"time"
)
func main() {
_ = godotenv.Load()
c := models2.Config{
Interval: time.Hour,
LogLevel: "info",
}
arg.MustParse(&c)
logger := log.NewJSONLogger(log.NewSyncWriter(os.Stdout))
logger = log.With(logger,
"ts", log.DefaultTimestampUTC,
"caller", log.Caller(5),
)
// level.SetKey("severity")
switch strings.ToLower(c.LogLevel) {
case "debug":
logger = level.NewFilter(logger, level.AllowDebug())
case "warn":
logger = level.NewFilter(logger, level.AllowWarn())
case "error":
logger = level.NewFilter(logger, level.AllowError())
default:
logger = level.NewFilter(logger, level.AllowInfo())
}
if len(c.Repositories) == 0 {
level.Error(logger).Log("msg", "no repositories to watch")
os.Exit(1)
}
checker := &Checker{
logger: logger,
tokens: map[string]string{Github: c.GithubAuthToken, Gitlab: c.GitlabAuthToken},
}
releases := make(chan models2.Repository)
go checker.Run(c.Interval, c.Repositories, releases)
slack := SlackSender{Hook: c.Hook, Username: c.Username, Icon: c.Icon}
level.Info(logger).Log("msg", "waiting for new releases")
for repository := range releases {
if c.IgnoreNonstable && repository.Release.IsNonstable() {
level.Debug(logger).Log("msg", "not notifying about non-stable version", "version", repository.Release.Name)
continue
}
if err := slack.Send(repository); err != nil {
level.Warn(logger).Log(
"msg", "failed to send release to messenger",
"err", err,
)
continue
}
}
}