aboutsummaryrefslogtreecommitdiffstats
path: root/modules/notification
diff options
context:
space:
mode:
Diffstat (limited to 'modules/notification')
-rw-r--r--modules/notification/base/notifier.go1
-rw-r--r--modules/notification/base/null.go4
-rw-r--r--modules/notification/notification.go7
-rw-r--r--modules/notification/webhook/webhook.go31
4 files changed, 43 insertions, 0 deletions
diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go
index 934ee80aa7..48846b3446 100644
--- a/modules/notification/base/notifier.go
+++ b/modules/notification/base/notifier.go
@@ -34,6 +34,7 @@ type Notifier interface {
NotifyMergePullRequest(*models.PullRequest, *models.User, *git.Repository)
NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest)
NotifyPullRequestReview(*models.PullRequest, *models.Review, *models.Comment)
+ NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string)
NotifyCreateIssueComment(*models.User, *models.Repository,
*models.Issue, *models.Comment)
diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go
index a04d0e8caa..bea4e55277 100644
--- a/modules/notification/base/null.go
+++ b/modules/notification/base/null.go
@@ -50,6 +50,10 @@ func (*NullNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models
func (*NullNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {
}
+// NotifyPullRequestChangeTargetBranch places a place holder function
+func (*NullNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) {
+}
+
// NotifyUpdateComment places a place holder function
func (*NullNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
}
diff --git a/modules/notification/notification.go b/modules/notification/notification.go
index ab671fa291..f567552df5 100644
--- a/modules/notification/notification.go
+++ b/modules/notification/notification.go
@@ -87,6 +87,13 @@ func NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comm
}
}
+// NotifyPullRequestChangeTargetBranch notifies when a pull request's target branch was changed
+func NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) {
+ for _, notifier := range notifiers {
+ notifier.NotifyPullRequestChangeTargetBranch(doer, pr, oldBranch)
+ }
+}
+
// NotifyUpdateComment notifies update comment to notifiers
func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
for _, notifier := range notifiers {
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go
index ee91a29f02..e0801445d8 100644
--- a/modules/notification/webhook/webhook.go
+++ b/modules/notification/webhook/webhook.go
@@ -559,6 +559,37 @@ func (*webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mod
}
}
+func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) {
+ issue := pr.Issue
+ if !issue.IsPull {
+ return
+ }
+ var err error
+
+ if err = issue.LoadPullRequest(); err != nil {
+ log.Error("LoadPullRequest failed: %v", err)
+ return
+ }
+ issue.PullRequest.Issue = issue
+ mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
+ err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueEdited,
+ Index: issue.Index,
+ Changes: &api.ChangesPayload{
+ Ref: &api.ChangesFromPayload{
+ From: oldBranch,
+ },
+ },
+ PullRequest: issue.PullRequest.APIFormat(),
+ Repository: issue.Repo.APIFormat(mode),
+ Sender: doer.APIFormat(),
+ })
+
+ if err != nil {
+ log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
+ }
+}
+
func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment) {
var reviewHookType models.HookEventType