@@ -25,8 +25,7 @@ func htmlLinkFormatter(url string, text string) string {
25
25
return fmt .Sprintf (`<a href="%s">%s</a>` , url , html .EscapeString (text ))
26
26
}
27
27
28
- func getIssuesPayloadInfo (p * api.IssuePayload , linkFormatter linkFormatter ) (string , string , string , int ) {
29
- senderLink := linkFormatter (setting .AppURL + p .Sender .UserName , p .Sender .UserName )
28
+ func getIssuesPayloadInfo (p * api.IssuePayload , linkFormatter linkFormatter , withSender bool ) (string , string , string , int ) {
30
29
repoLink := linkFormatter (p .Repository .HTMLURL , p .Repository .FullName )
31
30
issueTitle := fmt .Sprintf ("#%d %s" , p .Index , p .Issue .Title )
32
31
titleLink := linkFormatter (fmt .Sprintf ("%s/issues/%d" , p .Repository .HTMLURL , p .Index ), issueTitle )
@@ -35,34 +34,36 @@ func getIssuesPayloadInfo(p *api.IssuePayload, linkFormatter linkFormatter) (str
35
34
36
35
switch p .Action {
37
36
case api .HookIssueOpened :
38
- text = fmt .Sprintf ("[%s] Issue opened: %s by %s " , repoLink , titleLink , senderLink )
37
+ text = fmt .Sprintf ("[%s] Issue opened: %s" , repoLink , titleLink )
39
38
color = orangeColor
40
39
case api .HookIssueClosed :
41
- text = fmt .Sprintf ("[%s] Issue closed: %s by %s " , repoLink , titleLink , senderLink )
40
+ text = fmt .Sprintf ("[%s] Issue closed: %s" , repoLink , titleLink )
42
41
color = redColor
43
42
case api .HookIssueReOpened :
44
- text = fmt .Sprintf ("[%s] Issue re-opened: %s by %s " , repoLink , titleLink , senderLink )
43
+ text = fmt .Sprintf ("[%s] Issue re-opened: %s" , repoLink , titleLink )
45
44
case api .HookIssueEdited :
46
- text = fmt .Sprintf ("[%s] Issue edited: %s by %s " , repoLink , titleLink , senderLink )
45
+ text = fmt .Sprintf ("[%s] Issue edited: %s" , repoLink , titleLink )
47
46
case api .HookIssueAssigned :
48
- text = fmt .Sprintf ("[%s] Issue assigned to %s: %s by %s" , repoLink ,
49
- linkFormatter (setting .AppURL + p .Issue .Assignee .UserName , p .Issue .Assignee .UserName ),
50
- titleLink , senderLink )
47
+ text = fmt .Sprintf ("[%s] Issue assigned to %s: %s" , repoLink ,
48
+ linkFormatter (setting .AppURL + p .Issue .Assignee .UserName , p .Issue .Assignee .UserName ), titleLink )
51
49
color = greenColor
52
50
case api .HookIssueUnassigned :
53
- text = fmt .Sprintf ("[%s] Issue unassigned: %s by %s " , repoLink , titleLink , senderLink )
51
+ text = fmt .Sprintf ("[%s] Issue unassigned: %s" , repoLink , titleLink )
54
52
case api .HookIssueLabelUpdated :
55
- text = fmt .Sprintf ("[%s] Issue labels updated: %s by %s " , repoLink , titleLink , senderLink )
53
+ text = fmt .Sprintf ("[%s] Issue labels updated: %s" , repoLink , titleLink )
56
54
case api .HookIssueLabelCleared :
57
- text = fmt .Sprintf ("[%s] Issue labels cleared: %s by %s " , repoLink , titleLink , senderLink )
55
+ text = fmt .Sprintf ("[%s] Issue labels cleared: %s" , repoLink , titleLink )
58
56
case api .HookIssueSynchronized :
59
- text = fmt .Sprintf ("[%s] Issue synchronized: %s by %s " , repoLink , titleLink , senderLink )
57
+ text = fmt .Sprintf ("[%s] Issue synchronized: %s" , repoLink , titleLink )
60
58
case api .HookIssueMilestoned :
61
59
mileStoneLink := fmt .Sprintf ("%s/milestone/%d" , p .Repository .HTMLURL , p .Issue .Milestone .ID )
62
- text = fmt .Sprintf ("[%s] Issue milestoned to %s: %s by %s " , repoLink ,
63
- linkFormatter (mileStoneLink , p .Issue .Milestone .Title ), titleLink , senderLink )
60
+ text = fmt .Sprintf ("[%s] Issue milestoned to %s: %s" , repoLink ,
61
+ linkFormatter (mileStoneLink , p .Issue .Milestone .Title ), titleLink )
64
62
case api .HookIssueDemilestoned :
65
- text = fmt .Sprintf ("[%s] Issue milestone cleared: %s by %s" , repoLink , titleLink , senderLink )
63
+ text = fmt .Sprintf ("[%s] Issue milestone cleared: %s" , repoLink , titleLink )
64
+ }
65
+ if withSender {
66
+ text += fmt .Sprintf (" by %s" , linkFormatter (setting .AppURL + p .Sender .UserName , p .Sender .UserName ))
66
67
}
67
68
68
69
var attachmentText string
@@ -73,8 +74,7 @@ func getIssuesPayloadInfo(p *api.IssuePayload, linkFormatter linkFormatter) (str
73
74
return text , issueTitle , attachmentText , color
74
75
}
75
76
76
- func getPullRequestPayloadInfo (p * api.PullRequestPayload , linkFormatter linkFormatter ) (string , string , string , int ) {
77
- senderLink := linkFormatter (setting .AppURL + p .Sender .UserName , p .Sender .UserName )
77
+ func getPullRequestPayloadInfo (p * api.PullRequestPayload , linkFormatter linkFormatter , withSender bool ) (string , string , string , int ) {
78
78
repoLink := linkFormatter (p .Repository .HTMLURL , p .Repository .FullName )
79
79
issueTitle := fmt .Sprintf ("#%d %s" , p .Index , p .PullRequest .Title )
80
80
titleLink := linkFormatter (p .PullRequest .URL , issueTitle )
@@ -83,43 +83,45 @@ func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkForm
83
83
84
84
switch p .Action {
85
85
case api .HookIssueOpened :
86
- text = fmt .Sprintf ("[%s] Pull request %s opened by %s" , repoLink , titleLink , senderLink )
86
+ text = fmt .Sprintf ("[%s] Pull request opened: %s" , repoLink , titleLink )
87
87
color = greenColor
88
88
case api .HookIssueClosed :
89
89
if p .PullRequest .HasMerged {
90
- text = fmt .Sprintf ("[%s] Pull request %s merged by %s" , repoLink , titleLink , senderLink )
90
+ text = fmt .Sprintf ("[%s] Pull request merged: %s" , repoLink , titleLink )
91
91
color = purpleColor
92
92
} else {
93
- text = fmt .Sprintf ("[%s] Pull request %s closed by %s" , repoLink , titleLink , senderLink )
93
+ text = fmt .Sprintf ("[%s] Pull request closed: %s" , repoLink , titleLink )
94
94
color = redColor
95
95
}
96
96
case api .HookIssueReOpened :
97
- text = fmt .Sprintf ("[%s] Pull request %s re-opened by %s" , repoLink , titleLink , senderLink )
97
+ text = fmt .Sprintf ("[%s] Pull request re-opened: %s" , repoLink , titleLink )
98
98
case api .HookIssueEdited :
99
- text = fmt .Sprintf ("[%s] Pull request %s edited by %s" , repoLink , titleLink , senderLink )
99
+ text = fmt .Sprintf ("[%s] Pull request edited: %s" , repoLink , titleLink )
100
100
case api .HookIssueAssigned :
101
101
list := make ([]string , len (p .PullRequest .Assignees ))
102
102
for i , user := range p .PullRequest .Assignees {
103
103
list [i ] = linkFormatter (setting .AppURL + user .UserName , user .UserName )
104
104
}
105
- text = fmt .Sprintf ("[%s] Pull request %s assigned to %s by %s" , repoLink ,
106
- strings .Join (list , ", " ),
107
- titleLink , senderLink )
105
+ text = fmt .Sprintf ("[%s] Pull request assigned: %s to %s" , repoLink ,
106
+ strings .Join (list , ", " ), titleLink )
108
107
color = greenColor
109
108
case api .HookIssueUnassigned :
110
- text = fmt .Sprintf ("[%s] Pull request %s unassigned by %s" , repoLink , titleLink , senderLink )
109
+ text = fmt .Sprintf ("[%s] Pull request unassigned: %s" , repoLink , titleLink )
111
110
case api .HookIssueLabelUpdated :
112
- text = fmt .Sprintf ("[%s] Pull request %s labels updated by %s" , repoLink , titleLink , senderLink )
111
+ text = fmt .Sprintf ("[%s] Pull request labels updated: %s" , repoLink , titleLink )
113
112
case api .HookIssueLabelCleared :
114
- text = fmt .Sprintf ("[%s] Pull request %s labels cleared by %s" , repoLink , titleLink , senderLink )
113
+ text = fmt .Sprintf ("[%s] Pull request labels cleared: %s" , repoLink , titleLink )
115
114
case api .HookIssueSynchronized :
116
- text = fmt .Sprintf ("[%s] Pull request %s synchronized by %s" , repoLink , titleLink , senderLink )
115
+ text = fmt .Sprintf ("[%s] Pull request synchronized: %s" , repoLink , titleLink )
117
116
case api .HookIssueMilestoned :
118
117
mileStoneLink := fmt .Sprintf ("%s/milestone/%d" , p .Repository .HTMLURL , p .PullRequest .Milestone .ID )
119
- text = fmt .Sprintf ("[%s] Pull request %s milestoned to %s by %s" , repoLink ,
120
- linkFormatter (mileStoneLink , p .PullRequest .Milestone .Title ), titleLink , senderLink )
118
+ text = fmt .Sprintf ("[%s] Pull request milestoned: %s to %s" , repoLink ,
119
+ linkFormatter (mileStoneLink , p .PullRequest .Milestone .Title ), titleLink )
121
120
case api .HookIssueDemilestoned :
122
- text = fmt .Sprintf ("[%s] Pull request %s milestone cleared by %s" , repoLink , titleLink , senderLink )
121
+ text = fmt .Sprintf ("[%s] Pull request milestone cleared: %s" , repoLink , titleLink )
122
+ }
123
+ if withSender {
124
+ text += fmt .Sprintf (" by %s" , linkFormatter (setting .AppURL + p .Sender .UserName , p .Sender .UserName ))
123
125
}
124
126
125
127
var attachmentText string
@@ -130,28 +132,29 @@ func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkForm
130
132
return text , issueTitle , attachmentText , color
131
133
}
132
134
133
- func getReleasePayloadInfo (p * api.ReleasePayload , linkFormatter linkFormatter ) (text string , color int ) {
134
- senderLink := linkFormatter (setting .AppURL + p .Sender .UserName , p .Sender .UserName )
135
+ func getReleasePayloadInfo (p * api.ReleasePayload , linkFormatter linkFormatter , withSender bool ) (text string , color int ) {
135
136
repoLink := linkFormatter (p .Repository .HTMLURL , p .Repository .FullName )
136
137
refLink := linkFormatter (p .Repository .HTMLURL + "/src/" + p .Release .TagName , p .Release .TagName )
137
138
138
139
switch p .Action {
139
140
case api .HookReleasePublished :
140
- text = fmt .Sprintf ("[%s] Release %s created by %s" , repoLink , refLink , senderLink )
141
+ text = fmt .Sprintf ("[%s] Release created: %s" , repoLink , refLink )
141
142
color = greenColor
142
143
case api .HookReleaseUpdated :
143
- text = fmt .Sprintf ("[%s] Release %s updated by %s" , repoLink , refLink , senderLink )
144
+ text = fmt .Sprintf ("[%s] Release updated: %s" , repoLink , refLink )
144
145
color = yellowColor
145
146
case api .HookReleaseDeleted :
146
- text = fmt .Sprintf ("[%s] Release %s deleted by %s" , repoLink , refLink , senderLink )
147
+ text = fmt .Sprintf ("[%s] Release deleted: %s" , repoLink , refLink )
147
148
color = redColor
148
149
}
150
+ if withSender {
151
+ text += fmt .Sprintf (" by %s" , linkFormatter (setting .AppURL + p .Sender .UserName , p .Sender .UserName ))
152
+ }
149
153
150
154
return text , color
151
155
}
152
156
153
- func getIssueCommentPayloadInfo (p * api.IssueCommentPayload , linkFormatter linkFormatter ) (string , string , int ) {
154
- senderLink := linkFormatter (setting .AppURL + p .Sender .UserName , p .Sender .UserName )
157
+ func getIssueCommentPayloadInfo (p * api.IssueCommentPayload , linkFormatter linkFormatter , withSender bool ) (string , string , int ) {
155
158
repoLink := linkFormatter (p .Repository .HTMLURL , p .Repository .FullName )
156
159
issueTitle := fmt .Sprintf ("#%d %s" , p .Issue .Index , p .Issue .Title )
157
160
@@ -168,18 +171,21 @@ func getIssueCommentPayloadInfo(p *api.IssueCommentPayload, linkFormatter linkFo
168
171
169
172
switch p .Action {
170
173
case api .HookIssueCommentCreated :
171
- text = fmt .Sprintf ("[%s] New comment on %s %s by %s " , repoLink , typ , titleLink , senderLink )
174
+ text = fmt .Sprintf ("[%s] New comment on %s %s" , repoLink , typ , titleLink )
172
175
if p .IsPull {
173
176
color = greenColorLight
174
177
} else {
175
178
color = orangeColorLight
176
179
}
177
180
case api .HookIssueCommentEdited :
178
- text = fmt .Sprintf ("[%s] Comment on %s %s edited by %s " , repoLink , typ , titleLink , senderLink )
181
+ text = fmt .Sprintf ("[%s] Comment edited on %s %s" , repoLink , typ , titleLink )
179
182
case api .HookIssueCommentDeleted :
180
- text = fmt .Sprintf ("[%s] Comment on %s %s deleted by %s " , repoLink , typ , titleLink , senderLink )
183
+ text = fmt .Sprintf ("[%s] Comment deleted on %s %s" , repoLink , typ , titleLink )
181
184
color = redColor
182
185
}
186
+ if withSender {
187
+ text += fmt .Sprintf (" by %s" , linkFormatter (setting .AppURL + p .Sender .UserName , p .Sender .UserName ))
188
+ }
183
189
184
190
return text , issueTitle , color
185
191
}
0 commit comments