@@ -16,13 +16,15 @@ import (
16
16
"code.gitea.io/gitea/modules/setting"
17
17
)
18
18
19
+ // SlackMeta contains the slack metdata
19
20
type SlackMeta struct {
20
21
Channel string `json:"channel"`
21
22
Username string `json:"username"`
22
23
IconURL string `json:"icon_url"`
23
24
Color string `json:"color"`
24
25
}
25
26
27
+ // SlackPayload contains the information about the slack channel
26
28
type SlackPayload struct {
27
29
Channel string `json:"channel"`
28
30
Text string `json:"text"`
@@ -33,15 +35,18 @@ type SlackPayload struct {
33
35
Attachments []SlackAttachment `json:"attachments"`
34
36
}
35
37
38
+ // SlackAttachment contains the slack message
36
39
type SlackAttachment struct {
37
40
Fallback string `json:"fallback"`
38
41
Color string `json:"color"`
39
42
Title string `json:"title"`
40
43
Text string `json:"text"`
41
44
}
42
45
46
+ // SetSecret sets the slack secret
43
47
func (p * SlackPayload ) SetSecret (_ string ) {}
44
48
49
+ // JSONPayload Marshals the SlackPayload to json
45
50
func (p * SlackPayload ) JSONPayload () ([]byte , error ) {
46
51
data , err := json .MarshalIndent (p , "" , " " )
47
52
if err != nil {
@@ -50,6 +55,7 @@ func (p *SlackPayload) JSONPayload() ([]byte, error) {
50
55
return data , nil
51
56
}
52
57
58
+ // SlackTextFormatter replaces &, <, > with HTML characters
53
59
// see: https://api.slack.com/docs/formatting
54
60
func SlackTextFormatter (s string ) string {
55
61
// replace & < >
@@ -59,6 +65,7 @@ func SlackTextFormatter(s string) string {
59
65
return s
60
66
}
61
67
68
+ // SlackShortTextFormatter replaces &, <, > with HTML characters
62
69
func SlackShortTextFormatter (s string ) string {
63
70
s = strings .Split (s , "\n " )[0 ]
64
71
// replace & < >
@@ -68,6 +75,7 @@ func SlackShortTextFormatter(s string) string {
68
75
return s
69
76
}
70
77
78
+ // SlackLinkFormatter creates a link compatablie with slack
71
79
func SlackLinkFormatter (url string , text string ) string {
72
80
return fmt .Sprintf ("<%s|%s>" , url , SlackTextFormatter (text ))
73
81
}
@@ -181,6 +189,7 @@ func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*S
181
189
}, nil
182
190
}
183
191
192
+ // GetSlackPayload converts a slack webhook into a SlackPayload
184
193
func GetSlackPayload (p api.Payloader , event HookEventType , meta string ) (* SlackPayload , error ) {
185
194
s := new (SlackPayload )
186
195
0 commit comments