diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-10-28 13:26:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-28 13:26:46 +0800 |
commit | c66c9dabc7453febc0e01fcc974baf06fd96c38d (patch) | |
tree | 59709b9bd6c68cf4efaa5ed9b34a30cbde99d462 /modules/notification | |
parent | 495d5e4329326b27158a25b44c37986923d0bb6b (diff) | |
download | gitea-c66c9dabc7453febc0e01fcc974baf06fd96c38d.tar.gz gitea-c66c9dabc7453febc0e01fcc974baf06fd96c38d.zip |
Move issue change status from models to service (#8691)
Diffstat (limited to 'modules/notification')
-rw-r--r-- | modules/notification/webhook/webhook.go | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go index 704b42ec8d..1ee8473dd6 100644 --- a/modules/notification/webhook/webhook.go +++ b/modules/notification/webhook/webhook.go @@ -157,7 +157,6 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *mo } } else { mode, _ := models.AccessLevelUnit(doer, issue.Repo, models.UnitTypeIssues) - apiIssue := &api.IssuePayload{ Index: issue.Index, Issue: issue.APIFormat(), @@ -221,3 +220,45 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *model go models.HookQueue.Add(issue.RepoID) } } + +func (m *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) { + mode, _ := models.AccessLevel(issue.Poster, issue.Repo) + var err error + if issue.IsPull { + if err = issue.LoadPullRequest(); err != nil { + log.Error("LoadPullRequest: %v", err) + return + } + // Merge pull request calls issue.changeStatus so we need to handle separately. + apiPullRequest := &api.PullRequestPayload{ + Index: issue.Index, + PullRequest: issue.PullRequest.APIFormat(), + Repository: issue.Repo.APIFormat(mode), + Sender: doer.APIFormat(), + } + if isClosed { + apiPullRequest.Action = api.HookIssueClosed + } else { + apiPullRequest.Action = api.HookIssueReOpened + } + err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, apiPullRequest) + } else { + apiIssue := &api.IssuePayload{ + Index: issue.Index, + Issue: issue.APIFormat(), + Repository: issue.Repo.APIFormat(mode), + Sender: doer.APIFormat(), + } + if isClosed { + apiIssue.Action = api.HookIssueClosed + } else { + apiIssue.Action = api.HookIssueReOpened + } + err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, apiIssue) + } + if err != nil { + log.Error("PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err) + } else { + go models.HookQueue.Add(issue.Repo.ID) + } +} |