summaryrefslogtreecommitdiffstats
path: root/modules/notification
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-10-28 10:11:50 +0800
committerGitHub <noreply@github.com>2019-10-28 10:11:50 +0800
commit495d5e4329326b27158a25b44c37986923d0bb6b (patch)
treefa8474775eb9a1bdb11380ca17a9ca42a991fcb3 /modules/notification
parent018b0e818038f3c38cc6bfc96fadeb25c92380e6 (diff)
downloadgitea-495d5e4329326b27158a25b44c37986923d0bb6b.tar.gz
gitea-495d5e4329326b27158a25b44c37986923d0bb6b.zip
Move more issue assignee code from models to issue service (#8690)
* Move more issue assignee code from models to issue service * fix test
Diffstat (limited to 'modules/notification')
-rw-r--r--modules/notification/webhook/webhook.go92
1 files changed, 92 insertions, 0 deletions
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go
index 13f2f4486a..704b42ec8d 100644
--- a/modules/notification/webhook/webhook.go
+++ b/modules/notification/webhook/webhook.go
@@ -129,3 +129,95 @@ func (m *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models
go models.HookQueue.Add(repo.ID)
}
}
+
+func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
+ if issue.IsPull {
+ mode, _ := models.AccessLevelUnit(doer, issue.Repo, models.UnitTypePullRequests)
+
+ if err := issue.LoadPullRequest(); err != nil {
+ log.Error("LoadPullRequest failed: %v", err)
+ return
+ }
+ issue.PullRequest.Issue = issue
+ apiPullRequest := &api.PullRequestPayload{
+ Index: issue.Index,
+ PullRequest: issue.PullRequest.APIFormat(),
+ Repository: issue.Repo.APIFormat(mode),
+ Sender: doer.APIFormat(),
+ }
+ if removed {
+ apiPullRequest.Action = api.HookIssueUnassigned
+ } else {
+ apiPullRequest.Action = api.HookIssueAssigned
+ }
+ // Assignee comment triggers a webhook
+ if err := models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, apiPullRequest); err != nil {
+ log.Error("PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, removed, err)
+ return
+ }
+ } else {
+ mode, _ := models.AccessLevelUnit(doer, issue.Repo, models.UnitTypeIssues)
+
+ apiIssue := &api.IssuePayload{
+ Index: issue.Index,
+ Issue: issue.APIFormat(),
+ Repository: issue.Repo.APIFormat(mode),
+ Sender: doer.APIFormat(),
+ }
+ if removed {
+ apiIssue.Action = api.HookIssueUnassigned
+ } else {
+ apiIssue.Action = api.HookIssueAssigned
+ }
+ // Assignee comment triggers a webhook
+ if err := models.PrepareWebhooks(issue.Repo, models.HookEventIssues, apiIssue); err != nil {
+ log.Error("PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, removed, err)
+ return
+ }
+ }
+
+ go models.HookQueue.Add(issue.RepoID)
+}
+
+func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
+ mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
+ var err error
+ if issue.IsPull {
+ if err = issue.LoadPullRequest(); err != nil {
+ log.Error("LoadPullRequest failed: %v", err)
+ return
+ }
+ issue.PullRequest.Issue = issue
+ err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueEdited,
+ Index: issue.Index,
+ Changes: &api.ChangesPayload{
+ Title: &api.ChangesFromPayload{
+ From: oldTitle,
+ },
+ },
+ PullRequest: issue.PullRequest.APIFormat(),
+ Repository: issue.Repo.APIFormat(mode),
+ Sender: doer.APIFormat(),
+ })
+ } else {
+ err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
+ Action: api.HookIssueEdited,
+ Index: issue.Index,
+ Changes: &api.ChangesPayload{
+ Title: &api.ChangesFromPayload{
+ From: oldTitle,
+ },
+ },
+ Issue: issue.APIFormat(),
+ Repository: issue.Repo.APIFormat(mode),
+ Sender: issue.Poster.APIFormat(),
+ })
+ }
+
+ if err != nil {
+ log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
+ } else {
+ go models.HookQueue.Add(issue.RepoID)
+ }
+}