@@ -224,37 +224,88 @@ 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 {
228+ notifyIssueCommentChange (ctx , doer , comment , "" , webhook_module .HookEventPullRequestComment , api .HookIssueCommentCreated )
229+ return
230+ }
231+ notifyIssueCommentChange (ctx , doer , comment , "" , webhook_module .HookEventIssueComment , api .HookIssueCommentCreated )
232+ }
233+
234+ func (n * actionsNotifier ) UpdateComment (ctx context.Context , doer * user_model.User , c * issues_model.Comment , oldContent string ) {
235+ ctx = withMethod (ctx , "UpdateComment" )
236+
237+ if err := c .LoadIssue (ctx ); err != nil {
238+ log .Error ("LoadIssue: %v" , err )
239+ return
240+ }
241+
242+ if c .Issue .IsPull {
243+ notifyIssueCommentChange (ctx , doer , c , oldContent , webhook_module .HookEventPullRequestComment , api .HookIssueCommentEdited )
244+ return
245+ }
246+ notifyIssueCommentChange (ctx , doer , c , oldContent , webhook_module .HookEventIssueComment , api .HookIssueCommentEdited )
247+ }
248+
249+ func (n * actionsNotifier ) DeleteComment (ctx context.Context , doer * user_model.User , comment * issues_model.Comment ) {
250+ ctx = withMethod (ctx , "DeleteComment" )
251+
252+ if err := comment .LoadIssue (ctx ); err != nil {
253+ log .Error ("LoadIssue: %v" , err )
254+ return
255+ }
256+
257+ if comment .Issue .IsPull {
258+ notifyIssueCommentChange (ctx , doer , comment , "" , webhook_module .HookEventPullRequestComment , api .HookIssueCommentDeleted )
259+ return
260+ }
261+ notifyIssueCommentChange (ctx , doer , comment , "" , webhook_module .HookEventIssueComment , api .HookIssueCommentDeleted )
262+ }
263+
264+ func notifyIssueCommentChange (ctx context.Context , doer * user_model.User , comment * issues_model.Comment , oldContent string , event webhook_module.HookEventType , action api.HookIssueCommentAction ) {
265+ if err := comment .LoadIssue (ctx ); err != nil {
266+ log .Error ("LoadIssue: %v" , err )
267+ return
268+ }
269+ if err := comment .Issue .LoadAttributes (ctx ); err != nil {
270+ log .Error ("LoadAttributes: %v" , err )
271+ return
272+ }
273+
274+ permission , _ := access_model .GetUserRepoPermission (ctx , comment .Issue .Repo , doer )
275+
276+ payload := & api.IssueCommentPayload {
277+ Action : action ,
278+ Issue : convert .ToAPIIssue (ctx , comment .Issue ),
279+ Comment : convert .ToAPIComment (ctx , comment .Issue .Repo , comment ),
280+ Repository : convert .ToRepo (ctx , comment .Issue .Repo , permission ),
281+ Sender : convert .ToUser (ctx , doer , nil ),
282+ IsPull : comment .Issue .IsPull ,
283+ }
284+
285+ if action == api .HookIssueCommentEdited {
286+ payload .Changes = & api.ChangesPayload {
287+ Body : & api.ChangesFromPayload {
288+ From : oldContent ,
289+ },
290+ }
291+ }
292+
293+ if comment .Issue .IsPull {
294+ if err := comment .Issue .LoadPullRequest (ctx ); err != nil {
231295 log .Error ("LoadPullRequest: %v" , err )
232296 return
233297 }
234- newNotifyInputFromIssue (issue , webhook_module . HookEventPullRequestComment ).
298+ newNotifyInputFromIssue (comment . Issue , event ).
235299 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 ).
300+ WithPayload (payload ).
301+ WithPullRequest (comment .Issue .PullRequest ).
245302 Notify (ctx )
246303 return
247304 }
248- newNotifyInputFromIssue (issue , webhook_module .HookEventIssueComment ).
305+
306+ newNotifyInputFromIssue (comment .Issue , event ).
249307 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- }).
308+ WithPayload (payload ).
258309 Notify (ctx )
259310}
260311
@@ -496,7 +547,6 @@ func (n *actionsNotifier) DeleteRef(ctx context.Context, pusher *user_model.User
496547 apiRepo := convert .ToRepo (ctx , repo , access_model.Permission {AccessMode : perm_model .AccessModeNone })
497548
498549 newNotifyInput (repo , pusher , webhook_module .HookEventDelete ).
499- WithRef (refFullName .ShortName ()). // FIXME: should we use a full ref name
500550 WithPayload (& api.DeletePayload {
501551 Ref : refFullName .ShortName (),
502552 RefType : refFullName .RefType (),
0 commit comments