@@ -224,38 +224,11 @@ func (n *actionsNotifier) CreateIssueComment(ctx context.Context, doer *user_mod
224
224
) {
225
225
ctx = withMethod (ctx , "CreateIssueComment" )
226
226
227
- permission , _ := access_model .GetUserRepoPermission (ctx , repo , doer )
228
-
229
227
if issue .IsPull {
230
- if err := issue .LoadPullRequest (ctx ); err != nil {
231
- log .Error ("LoadPullRequest: %v" , err )
232
- return
233
- }
234
- newNotifyInputFromIssue (issue , webhook_module .HookEventPullRequestComment ).
235
- WithDoer (doer ).
236
- WithPayload (& api.IssueCommentPayload {
237
- Action : api .HookIssueCommentCreated ,
238
- Issue : convert .ToAPIIssue (ctx , issue ),
239
- Comment : convert .ToAPIComment (ctx , repo , comment ),
240
- Repository : convert .ToRepo (ctx , repo , permission ),
241
- Sender : convert .ToUser (ctx , doer , nil ),
242
- IsPull : true ,
243
- }).
244
- WithPullRequest (issue .PullRequest ).
245
- Notify (ctx )
228
+ notifyIssueCommentChange (ctx , doer , comment , "" , webhook_module .HookEventPullRequestComment , api .HookIssueCommentCreated )
246
229
return
247
230
}
248
- newNotifyInputFromIssue (issue , webhook_module .HookEventIssueComment ).
249
- WithDoer (doer ).
250
- WithPayload (& api.IssueCommentPayload {
251
- Action : api .HookIssueCommentCreated ,
252
- Issue : convert .ToAPIIssue (ctx , issue ),
253
- Comment : convert .ToAPIComment (ctx , repo , comment ),
254
- Repository : convert .ToRepo (ctx , repo , permission ),
255
- Sender : convert .ToUser (ctx , doer , nil ),
256
- IsPull : false ,
257
- }).
258
- Notify (ctx )
231
+ notifyIssueCommentChange (ctx , doer , comment , "" , webhook_module .HookEventIssueComment , api .HookIssueCommentCreated )
259
232
}
260
233
261
234
func (n * actionsNotifier ) UpdateComment (ctx context.Context , doer * user_model.User , c * issues_model.Comment , oldContent string ) {
@@ -265,49 +238,30 @@ func (n *actionsNotifier) UpdateComment(ctx context.Context, doer *user_model.Us
265
238
log .Error ("LoadIssue: %v" , err )
266
239
return
267
240
}
268
- if err := c .Issue .LoadAttributes (ctx ); err != nil {
269
- log .Error ("LoadAttributes: %v" , err )
241
+
242
+ if c .Issue .IsPull {
243
+ notifyIssueCommentChange (ctx , doer , c , oldContent , webhook_module .HookEventPullRequestComment , api .HookIssueCommentEdited )
270
244
return
271
245
}
246
+ notifyIssueCommentChange (ctx , doer , c , oldContent , webhook_module .HookEventIssueComment , api .HookIssueCommentEdited )
247
+ }
272
248
273
- permission , _ := access_model .GetUserRepoPermission (ctx , c .Issue .Repo , doer )
249
+ func (n * actionsNotifier ) DeleteComment (ctx context.Context , doer * user_model.User , comment * issues_model.Comment ) {
250
+ ctx = withMethod (ctx , "DeleteComment" )
274
251
275
- payload := & api.IssueCommentPayload {
276
- Action : api .HookIssueCommentEdited ,
277
- Issue : convert .ToAPIIssue (ctx , c .Issue ),
278
- Comment : convert .ToAPIComment (ctx , c .Issue .Repo , c ),
279
- Repository : convert .ToRepo (ctx , c .Issue .Repo , permission ),
280
- Changes : & api.ChangesPayload {
281
- Body : & api.ChangesFromPayload {
282
- From : oldContent ,
283
- },
284
- },
285
- Sender : convert .ToUser (ctx , doer , nil ),
286
- IsPull : c .Issue .IsPull ,
252
+ if err := comment .LoadIssue (ctx ); err != nil {
253
+ log .Error ("LoadIssue: %v" , err )
254
+ return
287
255
}
288
256
289
- if c .Issue .IsPull {
290
- if err := c .Issue .LoadPullRequest (ctx ); err != nil {
291
- log .Error ("LoadPullRequest: %v" , err )
292
- return
293
- }
294
- newNotifyInputFromIssue (c .Issue , webhook_module .HookEventPullRequestComment ).
295
- WithDoer (doer ).
296
- WithPayload (payload ).
297
- WithPullRequest (c .Issue .PullRequest ).
298
- Notify (ctx )
257
+ if comment .Issue .IsPull {
258
+ notifyIssueCommentChange (ctx , doer , comment , "" , webhook_module .HookEventPullRequestComment , api .HookIssueCommentDeleted )
299
259
return
300
260
}
301
-
302
- newNotifyInputFromIssue (c .Issue , webhook_module .HookEventIssueComment ).
303
- WithDoer (doer ).
304
- WithPayload (payload ).
305
- Notify (ctx )
261
+ notifyIssueCommentChange (ctx , doer , comment , "" , webhook_module .HookEventIssueComment , api .HookIssueCommentDeleted )
306
262
}
307
263
308
- func (n * actionsNotifier ) DeleteComment (ctx context.Context , doer * user_model.User , comment * issues_model.Comment ) {
309
- ctx = withMethod (ctx , "DeleteComment" )
310
-
264
+ func notifyIssueCommentChange (ctx context.Context , doer * user_model.User , comment * issues_model.Comment , oldContent string , event webhook_module.HookEventType , action api.HookIssueCommentAction ) {
311
265
if err := comment .LoadIssue (ctx ); err != nil {
312
266
log .Error ("LoadIssue: %v" , err )
313
267
return
@@ -320,28 +274,36 @@ func (n *actionsNotifier) DeleteComment(ctx context.Context, doer *user_model.Us
320
274
permission , _ := access_model .GetUserRepoPermission (ctx , comment .Issue .Repo , doer )
321
275
322
276
payload := & api.IssueCommentPayload {
323
- Action : api . HookIssueCommentDeleted ,
277
+ Action : action ,
324
278
Issue : convert .ToAPIIssue (ctx , comment .Issue ),
325
279
Comment : convert .ToAPIComment (ctx , comment .Issue .Repo , comment ),
326
280
Repository : convert .ToRepo (ctx , comment .Issue .Repo , permission ),
327
281
Sender : convert .ToUser (ctx , doer , nil ),
328
282
IsPull : comment .Issue .IsPull ,
329
283
}
330
284
285
+ if action == api .HookIssueCommentEdited {
286
+ payload .Changes = & api.ChangesPayload {
287
+ Body : & api.ChangesFromPayload {
288
+ From : oldContent ,
289
+ },
290
+ }
291
+ }
292
+
331
293
if comment .Issue .IsPull {
332
294
if err := comment .Issue .LoadPullRequest (ctx ); err != nil {
333
295
log .Error ("LoadPullRequest: %v" , err )
334
296
return
335
297
}
336
- newNotifyInputFromIssue (comment .Issue , webhook_module . HookEventPullRequestComment ).
298
+ newNotifyInputFromIssue (comment .Issue , event ).
337
299
WithDoer (doer ).
338
300
WithPayload (payload ).
339
301
WithPullRequest (comment .Issue .PullRequest ).
340
302
Notify (ctx )
341
303
return
342
304
}
343
305
344
- newNotifyInputFromIssue (comment .Issue , webhook_module . HookEventIssueComment ).
306
+ newNotifyInputFromIssue (comment .Issue , event ).
345
307
WithDoer (doer ).
346
308
WithPayload (payload ).
347
309
Notify (ctx )
0 commit comments