forked from bryannice/gitactions-slack-notification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (56 loc) · 1.47 KB
/
Copy pathmain.go
File metadata and controls
62 lines (56 loc) · 1.47 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
54
55
56
57
58
59
60
61
package main
import (
"github.com/bryannice/gitactions-slack-notification/command/notifier"
"github.com/bryannice/gitactions-slack-notification/configuration"
"github.com/pkg/errors"
"log"
)
func main() {
var err error
var config *configuration.Config
var slackMessage *notifier.Message
// Init configuration from environment variables
config = new(configuration.Config)
err = config.Init()
if err != nil {
log.Fatalf("Exception: %v", err)
}
slackMessage = new(notifier.Message)
slackMessage.Username = config.SlackUsername
slackMessage.IconURL = config.SlackIconUrl
slackMessage.Channel = config.SlackChannel
slackMessage.Attachments = []notifier.Attachment{
{
AuthorName: config.GithubActor,
AuthorLink: "http://github.com/" + config.GithubActor,
AuthorIconURL: "http://github.com/" + config.GithubActor + ".png?size=32",
Color: config.SlackColor,
Title: config.GithubEventName,
Fields: []notifier.Field{
{
Title: "Ref",
Value: config.GithubRef,
Short: true,
}, {
Title: "Event",
Value: config.GithubEventName,
Short: true,
},
{
Title: "Repo Action URL",
Value: "https://github.com/" + config.GithubRepository + "/actions",
Short: false,
},
{
Title: config.SlackTitle,
Value: config.SlackMessage,
Short: false,
},
},
},
}
err = slackMessage.Send(config.SlackWebhook)
if err != nil {
log.Printf("%+v", errors.Wrap(err, "Exception"))
}
}