Move webhook codes from service to webhook notification (#8712)
* Move webhook codes from service to webhook notification * move deletecomment webhook to notifications * fix notification
This commit is contained in:
parent
f694bb45d7
commit
ac6accef09
5 changed files with 94 additions and 83 deletions
|
@ -11,9 +11,8 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
)
|
||||
|
||||
|
@ -31,19 +30,8 @@ func CreateIssueComment(doer *models.User, repo *models.Repository, issue *model
|
|||
return nil, err
|
||||
}
|
||||
|
||||
mode, _ := models.AccessLevel(doer, repo)
|
||||
if err = models.PrepareWebhooks(repo, models.HookEventIssueComment, &api.IssueCommentPayload{
|
||||
Action: api.HookIssueCommentCreated,
|
||||
Issue: issue.APIFormat(),
|
||||
Comment: comment.APIFormat(),
|
||||
Repository: repo.APIFormat(mode),
|
||||
Sender: doer.APIFormat(),
|
||||
IsPull: issue.IsPull,
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
|
||||
} else {
|
||||
go models.HookQueue.Add(repo.ID)
|
||||
}
|
||||
notification.NotifyCreateIssueComment(doer, repo, issue, comment)
|
||||
|
||||
return comment, nil
|
||||
}
|
||||
|
||||
|
@ -106,35 +94,7 @@ func UpdateComment(c *models.Comment, doer *models.User, oldContent string) erro
|
|||
return err
|
||||
}
|
||||
|
||||
if err := c.LoadPoster(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.LoadIssue(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.Issue.LoadAttributes(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mode, _ := models.AccessLevel(doer, c.Issue.Repo)
|
||||
if err := models.PrepareWebhooks(c.Issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
|
||||
Action: api.HookIssueCommentEdited,
|
||||
Issue: c.Issue.APIFormat(),
|
||||
Comment: c.APIFormat(),
|
||||
Changes: &api.ChangesPayload{
|
||||
Body: &api.ChangesFromPayload{
|
||||
From: oldContent,
|
||||
},
|
||||
},
|
||||
Repository: c.Issue.Repo.APIFormat(mode),
|
||||
Sender: doer.APIFormat(),
|
||||
IsPull: c.Issue.IsPull,
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks [comment_id: %d]: %v", c.ID, err)
|
||||
} else {
|
||||
go models.HookQueue.Add(c.Issue.Repo.ID)
|
||||
}
|
||||
notification.NotifyUpdateComment(doer, c, oldContent)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -145,31 +105,7 @@ func DeleteComment(comment *models.Comment, doer *models.User) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := comment.LoadPoster(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := comment.LoadIssue(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := comment.Issue.LoadAttributes(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mode, _ := models.AccessLevel(doer, comment.Issue.Repo)
|
||||
|
||||
if err := models.PrepareWebhooks(comment.Issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
|
||||
Action: api.HookIssueCommentDeleted,
|
||||
Issue: comment.Issue.APIFormat(),
|
||||
Comment: comment.APIFormat(),
|
||||
Repository: comment.Issue.Repo.APIFormat(mode),
|
||||
Sender: doer.APIFormat(),
|
||||
IsPull: comment.Issue.IsPull,
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
|
||||
} else {
|
||||
go models.HookQueue.Add(comment.Issue.Repo.ID)
|
||||
}
|
||||
notification.NotifyDeleteComment(doer, comment)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue