diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-02 09:49:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-02 09:49:57 +0800 |
commit | 4b8d9e58c58b8952e86e7e5f90a0a8e0480e1de1 (patch) | |
tree | fc78aeb806eadd5bf3852612172c407d5b760dc0 /services/issue | |
parent | 484edb75836acdc0ea9c5e16737f0f1815c0a2b7 (diff) | |
download | gitea-4b8d9e58c58b8952e86e7e5f90a0a8e0480e1de1.tar.gz gitea-4b8d9e58c58b8952e86e7e5f90a0a8e0480e1de1.zip |
Move labels webhooks to notification (#8749)
* Move webhooks to notification
* fix notification
Diffstat (limited to 'services/issue')
-rw-r--r-- | services/issue/label.go | 55 |
1 files changed, 3 insertions, 52 deletions
diff --git a/services/issue/label.go b/services/issue/label.go index bb36d58492..5e154df959 100644 --- a/services/issue/label.go +++ b/services/issue/label.go @@ -6,58 +6,9 @@ package issue import ( "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" - api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/webhook" ) -func sendLabelUpdatedWebhook(issue *models.Issue, doer *models.User) { - var err error - - if err = issue.LoadRepo(); err != nil { - log.Error("LoadRepo: %v", err) - return - } - - if err = issue.LoadPoster(); err != nil { - log.Error("LoadPoster: %v", err) - return - } - - mode, _ := models.AccessLevel(issue.Poster, issue.Repo) - if issue.IsPull { - if err = issue.LoadPullRequest(); err != nil { - log.Error("loadPullRequest: %v", err) - return - } - if err = issue.PullRequest.LoadIssue(); err != nil { - log.Error("LoadIssue: %v", err) - return - } - err = webhook.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{ - Action: api.HookIssueLabelUpdated, - Index: issue.Index, - PullRequest: issue.PullRequest.APIFormat(), - Repository: issue.Repo.APIFormat(models.AccessModeNone), - Sender: doer.APIFormat(), - }) - } else { - err = webhook.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{ - Action: api.HookIssueLabelUpdated, - Index: issue.Index, - Issue: issue.APIFormat(), - Repository: issue.Repo.APIFormat(mode), - Sender: doer.APIFormat(), - }) - } - if err != nil { - log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) - } else { - go webhook.HookQueue.Add(issue.RepoID) - } -} - // ClearLabels clears all of an issue's labels func ClearLabels(issue *models.Issue, doer *models.User) (err error) { if err = issue.ClearLabels(doer); err != nil { @@ -75,7 +26,7 @@ func AddLabel(issue *models.Issue, doer *models.User, label *models.Label) error return err } - sendLabelUpdatedWebhook(issue, doer) + notification.NotifyIssueChangeLabels(doer, issue, []*models.Label{label}, nil) return nil } @@ -85,7 +36,7 @@ func AddLabels(issue *models.Issue, doer *models.User, labels []*models.Label) e return err } - sendLabelUpdatedWebhook(issue, doer) + notification.NotifyIssueChangeLabels(doer, issue, labels, nil) return nil } @@ -107,6 +58,6 @@ func RemoveLabel(issue *models.Issue, doer *models.User, label *models.Label) er return err } - sendLabelUpdatedWebhook(issue, doer) + notification.NotifyIssueChangeLabels(doer, issue, nil, []*models.Label{label}) return nil } |