-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
74 lines (63 loc) · 1.74 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
package main
import (
"fmt"
"github.com/nlopes/slack"
"github.com/urfave/cli"
"go.uber.org/zap"
"net/http"
"os"
)
var (
logger *zap.Logger
sugar *zap.SugaredLogger
service *GitHubService
)
func main() {
os.Exit(_main(os.Args[1:]))
}
func _main(_ []string) int {
logger, _ = zap.NewDevelopment()
defer logger.Sync()
sugar = logger.Sugar()
//var env envConfig
app := FlagSet()
app.Action = func(c *cli.Context) error {
if c.String("config") == "" {
return fmt.Errorf("required -c option")
}
// load config
config, err := LoadConfig(c.String("config"), c.String("region"))
if err != nil {
return fmt.Errorf("failed to load toml file: %s", err)
}
// FIXME: Pass Version.xcconfig path from env
config.InfoPlistPath = "Configurations/Version.xcconfig"
repo := GitHubRepository{Owner: config.GitHubRepositoryOwner, Name: config.GitHubRepositoryName}
author := CommitAuthor{Name: config.GitCommitAuthorName, Email: config.GitCommitAuthorEmail}
service = NewGitHubService(config.GitHubToken, repo, author, config.InfoPlistPath)
sugar.Infof("Start slack event listening")
client := slack.New(config.BotToken)
slackListener := &SlackListener{
client: client,
botID: config.BotID,
channelID: config.ChannelID,
debugChannelID: config.DebugChannelID,
}
go slackListener.ListenAndResponse()
http.Handle("/interaction", interactionHandler{
slackClient: client,
verificationToken: config.VerificationToken,
})
sugar.Infof("Server listening on :%s", c.String("port"))
if err := http.ListenAndServe(":"+c.String("port"), nil); err != nil {
return fmt.Errorf("%s", err)
}
return nil
}
err := app.Run(os.Args)
if err != nil {
sugar.Fatal(err)
return 1
}
return 0
}