-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.go
More file actions
91 lines (77 loc) · 1.54 KB
/
Copy pathplugin.go
File metadata and controls
91 lines (77 loc) · 1.54 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
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
package main
import (
rocket "github.com/revdaalex/go-rocket-webhook"
"strings"
)
type (
Repo struct {
Owner string
Name string
}
Build struct {
Tag string
Event string
Number int
Commit string
Ref string
Branch string
Author string
Pull string
Message string
DeployTo string
Status string
Link string
Started int64
Created int64
}
Config struct {
Webhook string
Channel string
Username string
EmojiIcon string
Text string
Color string
AttTitle string
AttTitleLink string
AttText string
}
Job struct {
Started int64
}
Plugin struct {
Repo Repo
Build Build
Config Config
Job Job
}
)
func (p Plugin) Exec() error {
if p.Config.AttTitle == "" {
p.Config.AttTitle = p.Repo.Name
}
if p.Config.AttText == "" {
p.Config.AttText = "tag: " + p.Build.Tag
}
attachment := rocket.Attachment{
Title: p.Config.AttTitle,
TitleLink: p.Config.AttTitleLink,
Text: p.Config.AttText,
Color: p.Config.Color,
}
payload := rocket.WebHookPostPayload{}
payload.Username = p.Config.Username
payload.Attachments = []*rocket.Attachment{&attachment}
payload.EmojiIcon = p.Config.EmojiIcon
payload.Text = p.Config.Text
if p.Config.Channel != "" {
payload.Channel = prepend("#", p.Config.Channel)
}
client := rocket.NewWebHook(p.Config.Webhook)
return client.PostMessage(&payload)
}
func prepend(prefix, s string) string {
if !strings.HasPrefix(s, prefix) {
return prefix + s
}
return s
}