@@ -132,41 +132,14 @@ func getDingtalkPushPayload(p *api.PushPayload) (*DingtalkPayload, error) {
132
132
}
133
133
134
134
func getDingtalkIssuesPayload (p * api.IssuePayload ) (* DingtalkPayload , error ) {
135
- var text , title string
136
- switch p .Action {
137
- case api .HookIssueOpened :
138
- title = fmt .Sprintf ("[%s] Issue opened: #%d %s" , p .Repository .FullName , p .Index , p .Issue .Title )
139
- text = p .Issue .Body
140
- case api .HookIssueClosed :
141
- title = fmt .Sprintf ("[%s] Issue closed: #%d %s" , p .Repository .FullName , p .Index , p .Issue .Title )
142
- case api .HookIssueReOpened :
143
- title = fmt .Sprintf ("[%s] Issue re-opened: #%d %s" , p .Repository .FullName , p .Index , p .Issue .Title )
144
- case api .HookIssueEdited :
145
- title = fmt .Sprintf ("[%s] Issue edited: #%d %s" , p .Repository .FullName , p .Index , p .Issue .Title )
146
- text = p .Issue .Body
147
- case api .HookIssueAssigned :
148
- title = fmt .Sprintf ("[%s] Issue assigned to %s: #%d %s" , p .Repository .FullName ,
149
- p .Issue .Assignee .UserName , p .Index , p .Issue .Title )
150
- case api .HookIssueUnassigned :
151
- title = fmt .Sprintf ("[%s] Issue unassigned: #%d %s" , p .Repository .FullName , p .Index , p .Issue .Title )
152
- case api .HookIssueLabelUpdated :
153
- title = fmt .Sprintf ("[%s] Issue labels updated: #%d %s" , p .Repository .FullName , p .Index , p .Issue .Title )
154
- case api .HookIssueLabelCleared :
155
- title = fmt .Sprintf ("[%s] Issue labels cleared: #%d %s" , p .Repository .FullName , p .Index , p .Issue .Title )
156
- case api .HookIssueSynchronized :
157
- title = fmt .Sprintf ("[%s] Issue synchronized: #%d %s" , p .Repository .FullName , p .Index , p .Issue .Title )
158
- case api .HookIssueMilestoned :
159
- title = fmt .Sprintf ("[%s] Issue milestone: #%d %s" , p .Repository .FullName , p .Index , p .Issue .Title )
160
- case api .HookIssueDemilestoned :
161
- title = fmt .Sprintf ("[%s] Issue clear milestone: #%d %s" , p .Repository .FullName , p .Index , p .Issue .Title )
162
- }
135
+ text , issueTitle , attachmentText , _ := getIssuesPayloadInfo (p , noneLinkFormatter )
163
136
164
137
return & DingtalkPayload {
165
138
MsgType : "actionCard" ,
166
139
ActionCard : dingtalk.ActionCard {
167
- Text : title + "\r \n \r \n " + text ,
140
+ Text : text + "\r \n \r \n " + attachmentText ,
168
141
//Markdown: "# " + title + "\n" + text,
169
- Title : title ,
142
+ Title : issueTitle ,
170
143
HideAvatar : "0" ,
171
144
SingleTitle : "view issue" ,
172
145
SingleURL : p .Issue .URL ,
@@ -175,93 +148,29 @@ func getDingtalkIssuesPayload(p *api.IssuePayload) (*DingtalkPayload, error) {
175
148
}
176
149
177
150
func getDingtalkIssueCommentPayload (p * api.IssueCommentPayload ) (* DingtalkPayload , error ) {
178
- title := fmt .Sprintf ("#%d: %s" , p .Issue .Index , p .Issue .Title )
179
- url := fmt .Sprintf ("%s/issues/%d#%s" , p .Repository .HTMLURL , p .Issue .Index , models .CommentHashTag (p .Comment .ID ))
180
- var content string
181
- switch p .Action {
182
- case api .HookIssueCommentCreated :
183
- if p .IsPull {
184
- title = "New comment on pull request " + title
185
- } else {
186
- title = "New comment on issue " + title
187
- }
188
- content = p .Comment .Body
189
- case api .HookIssueCommentEdited :
190
- if p .IsPull {
191
- title = "Comment edited on pull request " + title
192
- } else {
193
- title = "Comment edited on issue " + title
194
- }
195
- content = p .Comment .Body
196
- case api .HookIssueCommentDeleted :
197
- if p .IsPull {
198
- title = "Comment deleted on pull request " + title
199
- } else {
200
- title = "Comment deleted on issue " + title
201
- }
202
- url = fmt .Sprintf ("%s/issues/%d" , p .Repository .HTMLURL , p .Issue .Index )
203
- content = p .Comment .Body
204
- }
205
-
206
- title = fmt .Sprintf ("[%s] %s" , p .Repository .FullName , title )
151
+ text , issueTitle , _ := getIssueCommentPayloadInfo (p , noneLinkFormatter )
207
152
208
153
return & DingtalkPayload {
209
154
MsgType : "actionCard" ,
210
155
ActionCard : dingtalk.ActionCard {
211
- Text : title + "\r \n \r \n " + content ,
212
- Title : title ,
156
+ Text : text + "\r \n \r \n " + p . Comment . Body ,
157
+ Title : issueTitle ,
213
158
HideAvatar : "0" ,
214
159
SingleTitle : "view issue comment" ,
215
- SingleURL : url ,
160
+ SingleURL : p . Comment . HTMLURL ,
216
161
},
217
162
}, nil
218
163
}
219
164
220
165
func getDingtalkPullRequestPayload (p * api.PullRequestPayload ) (* DingtalkPayload , error ) {
221
- var text , title string
222
- switch p .Action {
223
- case api .HookIssueOpened :
224
- title = fmt .Sprintf ("[%s] Pull request opened: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
225
- text = p .PullRequest .Body
226
- case api .HookIssueClosed :
227
- if p .PullRequest .HasMerged {
228
- title = fmt .Sprintf ("[%s] Pull request merged: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
229
- } else {
230
- title = fmt .Sprintf ("[%s] Pull request closed: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
231
- }
232
- case api .HookIssueReOpened :
233
- title = fmt .Sprintf ("[%s] Pull request re-opened: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
234
- case api .HookIssueEdited :
235
- title = fmt .Sprintf ("[%s] Pull request edited: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
236
- text = p .PullRequest .Body
237
- case api .HookIssueAssigned :
238
- list := make ([]string , len (p .PullRequest .Assignees ))
239
- for i , user := range p .PullRequest .Assignees {
240
- list [i ] = user .UserName
241
- }
242
- title = fmt .Sprintf ("[%s] Pull request assigned to %s: #%d %s" , p .Repository .FullName ,
243
- strings .Join (list , ", " ),
244
- p .Index , p .PullRequest .Title )
245
- case api .HookIssueUnassigned :
246
- title = fmt .Sprintf ("[%s] Pull request unassigned: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
247
- case api .HookIssueLabelUpdated :
248
- title = fmt .Sprintf ("[%s] Pull request labels updated: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
249
- case api .HookIssueLabelCleared :
250
- title = fmt .Sprintf ("[%s] Pull request labels cleared: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
251
- case api .HookIssueSynchronized :
252
- title = fmt .Sprintf ("[%s] Pull request synchronized: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
253
- case api .HookIssueMilestoned :
254
- title = fmt .Sprintf ("[%s] Pull request milestone: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
255
- case api .HookIssueDemilestoned :
256
- title = fmt .Sprintf ("[%s] Pull request clear milestone: #%d %s" , p .Repository .FullName , p .Index , p .PullRequest .Title )
257
- }
166
+ text , issueTitle , attachmentText , _ := getPullRequestPayloadInfo (p , noneLinkFormatter )
258
167
259
168
return & DingtalkPayload {
260
169
MsgType : "actionCard" ,
261
170
ActionCard : dingtalk.ActionCard {
262
- Text : title + "\r \n \r \n " + text ,
171
+ Text : text + "\r \n \r \n " + attachmentText ,
263
172
//Markdown: "# " + title + "\n" + text,
264
- Title : title ,
173
+ Title : issueTitle ,
265
174
HideAvatar : "0" ,
266
175
SingleTitle : "view pull request" ,
267
176
SingleURL : p .PullRequest .HTMLURL ,
@@ -327,51 +236,18 @@ func getDingtalkRepositoryPayload(p *api.RepositoryPayload) (*DingtalkPayload, e
327
236
}
328
237
329
238
func getDingtalkReleasePayload (p * api.ReleasePayload ) (* DingtalkPayload , error ) {
330
- var title , url string
331
- switch p .Action {
332
- case api .HookReleasePublished :
333
- title = fmt .Sprintf ("[%s] Release created" , p .Release .TagName )
334
- url = p .Release .URL
335
- return & DingtalkPayload {
336
- MsgType : "actionCard" ,
337
- ActionCard : dingtalk.ActionCard {
338
- Text : title ,
339
- Title : title ,
340
- HideAvatar : "0" ,
341
- SingleTitle : "view release" ,
342
- SingleURL : url ,
343
- },
344
- }, nil
345
- case api .HookReleaseUpdated :
346
- title = fmt .Sprintf ("[%s] Release updated" , p .Release .TagName )
347
- url = p .Release .URL
348
- return & DingtalkPayload {
349
- MsgType : "actionCard" ,
350
- ActionCard : dingtalk.ActionCard {
351
- Text : title ,
352
- Title : title ,
353
- HideAvatar : "0" ,
354
- SingleTitle : "view release" ,
355
- SingleURL : url ,
356
- },
357
- }, nil
239
+ text , _ := getReleasePayloadInfo (p , noneLinkFormatter )
358
240
359
- case api .HookReleaseDeleted :
360
- title = fmt .Sprintf ("[%s] Release deleted" , p .Release .TagName )
361
- url = p .Release .URL
362
- return & DingtalkPayload {
363
- MsgType : "actionCard" ,
364
- ActionCard : dingtalk.ActionCard {
365
- Text : title ,
366
- Title : title ,
367
- HideAvatar : "0" ,
368
- SingleTitle : "view release" ,
369
- SingleURL : url ,
370
- },
371
- }, nil
372
- }
373
-
374
- return nil , nil
241
+ return & DingtalkPayload {
242
+ MsgType : "actionCard" ,
243
+ ActionCard : dingtalk.ActionCard {
244
+ Text : text ,
245
+ Title : text ,
246
+ HideAvatar : "0" ,
247
+ SingleTitle : "view release" ,
248
+ SingleURL : p .Release .URL ,
249
+ },
250
+ }, nil
375
251
}
376
252
377
253
// GetDingtalkPayload converts a ding talk webhook into a DingtalkPayload
0 commit comments