diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/notification/base/notifier.go | 2 | ||||
-rw-r--r-- | modules/notification/base/null.go | 2 | ||||
-rw-r--r-- | modules/notification/notification.go | 4 | ||||
-rw-r--r-- | modules/notification/webhook/webhook.go | 42 |
4 files changed, 46 insertions, 4 deletions
diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index c74bb52014..b0e7b4cae8 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -20,7 +20,7 @@ type Notifier interface { NotifyNewIssue(*models.Issue) NotifyIssueChangeStatus(*models.User, *models.Issue, bool) - NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) + NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index 9fb08884a1..3524a53c15 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -75,7 +75,7 @@ func (*NullNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) } // NotifyIssueChangeMilestone places a place holder function -func (*NullNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) { +func (*NullNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { } // NotifyIssueChangeContent places a place holder function diff --git a/modules/notification/notification.go b/modules/notification/notification.go index 0f1b63cf67..70b1541e35 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -128,9 +128,9 @@ func NotifyDeleteRelease(doer *models.User, rel *models.Release) { } // NotifyIssueChangeMilestone notifies change milestone to notifiers -func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) { +func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { for _, notifier := range notifiers { - notifier.NotifyIssueChangeMilestone(doer, issue) + notifier.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID) } } diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go index 259b6352ab..a969ad74f7 100644 --- a/modules/notification/webhook/webhook.go +++ b/modules/notification/webhook/webhook.go @@ -419,3 +419,45 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *mode log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) } } + +func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { + var hookAction api.HookIssueAction + var err error + if issue.MilestoneID > 0 { + hookAction = api.HookIssueMilestoned + } else { + hookAction = api.HookIssueDemilestoned + } + + if err = issue.LoadAttributes(); err != nil { + log.Error("issue.LoadAttributes failed: %v", err) + return + } + + mode, _ := models.AccessLevel(doer, issue.Repo) + if issue.IsPull { + err = issue.PullRequest.LoadIssue() + if err != nil { + log.Error("LoadIssue: %v", err) + return + } + err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{ + Action: hookAction, + Index: issue.Index, + PullRequest: issue.PullRequest.APIFormat(), + Repository: issue.Repo.APIFormat(mode), + Sender: doer.APIFormat(), + }) + } else { + err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{ + Action: hookAction, + 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) + } +} |