Skip to content

Commit e92f28f

Browse files
committed
move deletecomment webhook to notifications
1 parent 46c3273 commit e92f28f

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

modules/notification/webhook/webhook.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,34 @@ func (m *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *mode
367367
go models.HookQueue.Add(repo.ID)
368368
}
369369
}
370+
371+
func (m *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) {
372+
if err := comment.LoadPoster(); err != nil {
373+
log.Error("LoadPoster: %v", err)
374+
return
375+
}
376+
if err := comment.LoadIssue(); err != nil {
377+
log.Error("LoadIssue: %v", err)
378+
return
379+
}
380+
381+
if err := comment.Issue.LoadAttributes(); err != nil {
382+
log.Error("LoadAttributes: %v", err)
383+
return
384+
}
385+
386+
mode, _ := models.AccessLevel(doer, comment.Issue.Repo)
387+
388+
if err := models.PrepareWebhooks(comment.Issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
389+
Action: api.HookIssueCommentDeleted,
390+
Issue: comment.Issue.APIFormat(),
391+
Comment: comment.APIFormat(),
392+
Repository: comment.Issue.Repo.APIFormat(mode),
393+
Sender: doer.APIFormat(),
394+
IsPull: comment.Issue.IsPull,
395+
}); err != nil {
396+
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
397+
} else {
398+
go models.HookQueue.Add(comment.Issue.Repo.ID)
399+
}
400+
}

routers/api/v1/repo/issue_comment.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"code.gitea.io/gitea/models"
1212
"code.gitea.io/gitea/modules/context"
13-
"code.gitea.io/gitea/modules/notification"
1413
api "code.gitea.io/gitea/modules/structs"
1514
comment_service "code.gitea.io/gitea/services/comments"
1615
)
@@ -392,7 +391,5 @@ func deleteIssueComment(ctx *context.APIContext) {
392391
return
393392
}
394393

395-
notification.NotifyDeleteComment(ctx.User, comment)
396-
397394
ctx.Status(204)
398395
}

routers/repo/issue.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,13 +1400,11 @@ func DeleteComment(ctx *context.Context) {
14001400
return
14011401
}
14021402

1403-
if err = models.DeleteComment(comment, ctx.User); err != nil {
1403+
if err = comment_service.DeleteComment(comment, ctx.User); err != nil {
14041404
ctx.ServerError("DeleteCommentByID", err)
14051405
return
14061406
}
14071407

1408-
notification.NotifyDeleteComment(ctx.User, comment)
1409-
14101408
ctx.Status(200)
14111409
}
14121410

services/comments/comments.go

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import (
1111

1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/modules/git"
14-
"code.gitea.io/gitea/modules/log"
1514
"code.gitea.io/gitea/modules/notification"
1615
"code.gitea.io/gitea/modules/setting"
17-
api "code.gitea.io/gitea/modules/structs"
1816
"code.gitea.io/gitea/services/gitdiff"
1917
)
2018

@@ -107,31 +105,7 @@ func DeleteComment(comment *models.Comment, doer *models.User) error {
107105
return err
108106
}
109107

110-
if err := comment.LoadPoster(); err != nil {
111-
return err
112-
}
113-
if err := comment.LoadIssue(); err != nil {
114-
return err
115-
}
116-
117-
if err := comment.Issue.LoadAttributes(); err != nil {
118-
return err
119-
}
120-
121-
mode, _ := models.AccessLevel(doer, comment.Issue.Repo)
122-
123-
if err := models.PrepareWebhooks(comment.Issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
124-
Action: api.HookIssueCommentDeleted,
125-
Issue: comment.Issue.APIFormat(),
126-
Comment: comment.APIFormat(),
127-
Repository: comment.Issue.Repo.APIFormat(mode),
128-
Sender: doer.APIFormat(),
129-
IsPull: comment.Issue.IsPull,
130-
}); err != nil {
131-
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
132-
} else {
133-
go models.HookQueue.Add(comment.Issue.Repo.ID)
134-
}
108+
notification.NotifyDeleteComment(doer, comment)
135109

136110
return nil
137111
}

0 commit comments

Comments
 (0)