summaryrefslogtreecommitdiffstats
path: root/modules/notification
diff options
context:
space:
mode:
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)
+ }
+}