-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
98 lines (82 loc) · 2.23 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"flag"
"net/http"
"time"
log "github.com/sirupsen/logrus"
"github.com/zvlb/release-watcher/internal/config"
"github.com/zvlb/release-watcher/internal/providers"
"github.com/zvlb/release-watcher/internal/providers/github"
"github.com/zvlb/release-watcher/internal/recievers"
"github.com/zvlb/release-watcher/internal/recievers/slack"
"github.com/zvlb/release-watcher/internal/recievers/telegram"
)
func main() {
var configFile string
flag.StringVar(&configFile, "config-file", "/release-watcher/config.yaml", "Config file.")
flag.Parse()
cfg, err := config.GetConfiguration(configFile)
if err != nil {
panic(err)
}
err = StartWatchers(cfg)
if err != nil {
panic(err)
}
}
func StartWatchers(cfg config.Config) error {
recievers := generateRecievers(cfg)
providers, err := generateProviders(cfg)
if err != nil {
return err
}
// Start for GitHub Providers
for _, p := range providers {
go Watcher(p, recievers)
}
for {
time.Sleep(time.Hour * 100)
}
}
func Watcher(provired providers.Provider, recievers []recievers.Reciever) error {
log.Infof("Start Release Watch for %v", provired.GetName())
for {
name, release, description, link, err := provired.WatchReleases()
if err != nil {
return err
}
log.Infof("Find New Release for %v", provired.GetName())
for _, r := range recievers {
err = r.SendData(name, release, description, link)
if err != nil {
log.Infof("Can't send data to reciever %s with error: %v", r.GetName(), err)
}
}
}
}
func generateRecievers(cfg config.Config) []recievers.Reciever {
recievers := []recievers.Reciever{}
// Get telegram Recievers
for _, t := range cfg.Recievers.Telegram {
r := telegram.New(t.Token, t.ChatID, cfg)
recievers = append(recievers, r)
}
// Get slack Recievers
for _, t := range cfg.Recievers.Slack {
r := slack.New(t.ChannelName, t.Hook, cfg)
recievers = append(recievers, r)
}
return recievers
}
func generateProviders(cfg config.Config) ([]providers.Provider, error) {
providers := []providers.Provider{}
// Get github Provides
for _, g := range cfg.Releases.Github {
p, err := github.New(g, &http.Client{})
if err != nil {
return providers, err
}
providers = append(providers, p)
}
return providers, nil
}