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