@@ -224,38 +224,11 @@ func (n *actionsNotifier) CreateIssueComment(ctx context.Context, doer *user_mod
224224) {
225225 ctx = withMethod (ctx , "CreateIssueComment" )
226226
227- permission , _ := access_model .GetUserRepoPermission (ctx , repo , doer )
228-
229227 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 )
246229 return
247230 }
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 )
259232}
260233
261234func (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
265238 log .Error ("LoadIssue: %v" , err )
266239 return
267240 }
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 )
270244 return
271245 }
246+ notifyIssueCommentChange (ctx , doer , c , oldContent , webhook_module .HookEventIssueComment , api .HookIssueCommentEdited )
247+ }
272248
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" )
274251
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
287255 }
288256
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 )
299259 return
300260 }
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 )
306262}
307263
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 ) {
311265 if err := comment .LoadIssue (ctx ); err != nil {
312266 log .Error ("LoadIssue: %v" , err )
313267 return
@@ -320,28 +274,36 @@ func (n *actionsNotifier) DeleteComment(ctx context.Context, doer *user_model.Us
320274 permission , _ := access_model .GetUserRepoPermission (ctx , comment .Issue .Repo , doer )
321275
322276 payload := & api.IssueCommentPayload {
323- Action : api . HookIssueCommentDeleted ,
277+ Action : action ,
324278 Issue : convert .ToAPIIssue (ctx , comment .Issue ),
325279 Comment : convert .ToAPIComment (ctx , comment .Issue .Repo , comment ),
326280 Repository : convert .ToRepo (ctx , comment .Issue .Repo , permission ),
327281 Sender : convert .ToUser (ctx , doer , nil ),
328282 IsPull : comment .Issue .IsPull ,
329283 }
330284
285+ if action == api .HookIssueCommentEdited {
286+ payload .Changes = & api.ChangesPayload {
287+ Body : & api.ChangesFromPayload {
288+ From : oldContent ,
289+ },
290+ }
291+ }
292+
331293 if comment .Issue .IsPull {
332294 if err := comment .Issue .LoadPullRequest (ctx ); err != nil {
333295 log .Error ("LoadPullRequest: %v" , err )
334296 return
335297 }
336- newNotifyInputFromIssue (comment .Issue , webhook_module . HookEventPullRequestComment ).
298+ newNotifyInputFromIssue (comment .Issue , event ).
337299 WithDoer (doer ).
338300 WithPayload (payload ).
339301 WithPullRequest (comment .Issue .PullRequest ).
340302 Notify (ctx )
341303 return
342304 }
343305
344- newNotifyInputFromIssue (comment .Issue , webhook_module . HookEventIssueComment ).
306+ newNotifyInputFromIssue (comment .Issue , event ).
345307 WithDoer (doer ).
346308 WithPayload (payload ).
347309 Notify (ctx )
0 commit comments