diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-05 19:04:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-05 19:04:08 +0800 |
commit | aaeef295bb07b281fe0554aa6e97f24596d073aa (patch) | |
tree | 6df2fb31d6d3f3d50a14e1a992ab3f719683a658 /services/pull | |
parent | 05e7715c4b2af174aefc56fe459e5c08a96a3017 (diff) | |
download | gitea-aaeef295bb07b281fe0554aa6e97f24596d073aa.tar.gz gitea-aaeef295bb07b281fe0554aa6e97f24596d073aa.zip |
Move pull webhook to notification (#8805)
* Move pull webhook to notification
* fix fmt
Diffstat (limited to 'services/pull')
-rw-r--r-- | services/pull/merge.go | 14 | ||||
-rw-r--r-- | services/pull/pull.go | 18 | ||||
-rw-r--r-- | services/pull/review.go | 47 |
3 files changed, 9 insertions, 70 deletions
diff --git a/services/pull/merge.go b/services/pull/merge.go index 4a2f4511c4..c6607910a2 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -20,10 +20,9 @@ import ( "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" - api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" - "code.gitea.io/gitea/modules/webhook" "github.com/mcuadros/go-version" ) @@ -360,16 +359,7 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor return nil } - mode, _ := models.AccessLevel(doer, pr.Issue.Repo) - if err = webhook.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{ - Action: api.HookIssueClosed, - Index: pr.Index, - PullRequest: pr.APIFormat(), - Repository: pr.Issue.Repo.APIFormat(mode), - Sender: doer.APIFormat(), - }); err != nil { - log.Error("PrepareWebhooks: %v", err) - } + notification.NotifyIssueChangeStatus(doer, pr.Issue, true) return nil } diff --git a/services/pull/pull.go b/services/pull/pull.go index 20939c397f..4e981b2b26 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -11,8 +11,6 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" - api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/webhook" issue_service "code.gitea.io/gitea/services/issue" ) @@ -90,23 +88,9 @@ func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSy if err == nil { for _, pr := range prs { pr.Issue.PullRequest = pr - if err = pr.Issue.LoadAttributes(); err != nil { - log.Error("LoadAttributes: %v", err) - continue - } - if err = webhook.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{ - Action: api.HookIssueSynchronized, - Index: pr.Issue.Index, - PullRequest: pr.Issue.PullRequest.APIFormat(), - Repository: pr.Issue.Repo.APIFormat(models.AccessModeNone), - Sender: doer.APIFormat(), - }); err != nil { - log.Error("PrepareWebhooks [pull_id: %v]: %v", pr.ID, err) - continue - } + notification.NotifyPullRequestSynchronized(doer, pr) } } - } addHeadRepoTasks(prs) diff --git a/services/pull/review.go b/services/pull/review.go index ffb7be82b2..e4aae3c0d5 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -7,8 +7,7 @@ package pull import ( "code.gitea.io/gitea/models" - api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/webhook" + "code.gitea.io/gitea/modules/notification" ) // CreateReview creates a new review based on opts @@ -18,7 +17,9 @@ func CreateReview(opts models.CreateReviewOptions) (*models.Review, error) { return nil, err } - return review, reviewHook(review) + notification.NotifyPullRequestReview(review.Issue.PullRequest, review, nil) + + return review, nil } // UpdateReview updates a review @@ -28,43 +29,7 @@ func UpdateReview(review *models.Review) error { return err } - return reviewHook(review) -} - -func reviewHook(review *models.Review) error { - var reviewHookType models.HookEventType - - switch review.Type { - case models.ReviewTypeApprove: - reviewHookType = models.HookEventPullRequestApproved - case models.ReviewTypeComment: - reviewHookType = models.HookEventPullRequestComment - case models.ReviewTypeReject: - reviewHookType = models.HookEventPullRequestRejected - default: - // unsupported review webhook type here - return nil - } - - pr := review.Issue.PullRequest + notification.NotifyPullRequestReview(review.Issue.PullRequest, review, nil) - if err := pr.LoadIssue(); err != nil { - return err - } - - mode, err := models.AccessLevel(review.Issue.Poster, review.Issue.Repo) - if err != nil { - return err - } - return webhook.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{ - Action: api.HookIssueSynchronized, - Index: review.Issue.Index, - PullRequest: pr.APIFormat(), - Repository: review.Issue.Repo.APIFormat(mode), - Sender: review.Reviewer.APIFormat(), - Review: &api.ReviewPayload{ - Type: string(reviewHookType), - Content: review.Content, - }, - }) + return nil } |