summaryrefslogtreecommitdiffstats
path: root/services/pull
diff options
context:
space:
mode:
authorJohn Olheiser <42128690+jolheiser@users.noreply.github.com>2019-10-18 03:33:19 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2019-10-18 16:33:19 +0800
commit7c4c01c0fda90d94cf3785f27b505d9fc502fee6 (patch)
tree073304af25f97daf419932f795668e333923eab5 /services/pull
parentd44053eeda9128fb2e8f74205db6b998e7820fa2 (diff)
downloadgitea-7c4c01c0fda90d94cf3785f27b505d9fc502fee6.tar.gz
gitea-7c4c01c0fda90d94cf3785f27b505d9fc502fee6.zip
Fix review webhooks (#8570)
Signed-off-by: jolheiser <john.olheiser@gmail.com>
Diffstat (limited to 'services/pull')
-rw-r--r--services/pull/review.go40
1 files changed, 27 insertions, 13 deletions
diff --git a/services/pull/review.go b/services/pull/review.go
index 3fdfaaff84..261c2d32d2 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -17,9 +17,23 @@ func CreateReview(opts models.CreateReviewOptions) (*models.Review, error) {
return nil, err
}
+ return review, reviewHook(review)
+}
+
+// UpdateReview updates a review
+func UpdateReview(review *models.Review) error {
+ err := models.UpdateReview(review)
+ if err != nil {
+ return err
+ }
+
+ return reviewHook(review)
+}
+
+func reviewHook(review *models.Review) error {
var reviewHookType models.HookEventType
- switch opts.Type {
+ switch review.Type {
case models.ReviewTypeApprove:
reviewHookType = models.HookEventPullRequestApproved
case models.ReviewTypeComment:
@@ -28,30 +42,30 @@ func CreateReview(opts models.CreateReviewOptions) (*models.Review, error) {
reviewHookType = models.HookEventPullRequestRejected
default:
// unsupported review webhook type here
- return review, nil
+ return nil
}
- pr := opts.Issue.PullRequest
+ pr := review.Issue.PullRequest
if err := pr.LoadIssue(); err != nil {
- return nil, err
+ return err
}
- mode, err := models.AccessLevel(opts.Issue.Poster, opts.Issue.Repo)
+ mode, err := models.AccessLevel(review.Issue.Poster, review.Issue.Repo)
if err != nil {
- return nil, err
+ return err
}
- if err := models.PrepareWebhooks(opts.Issue.Repo, reviewHookType, &api.PullRequestPayload{
+ if err := models.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{
Action: api.HookIssueSynchronized,
- Index: opts.Issue.Index,
+ Index: review.Issue.Index,
PullRequest: pr.APIFormat(),
- Repository: opts.Issue.Repo.APIFormat(mode),
- Sender: opts.Reviewer.APIFormat(),
+ Repository: review.Issue.Repo.APIFormat(mode),
+ Sender: review.Reviewer.APIFormat(),
}); err != nil {
- return nil, err
+ return err
}
- go models.HookQueue.Add(opts.Issue.Repo.ID)
+ go models.HookQueue.Add(review.Issue.Repo.ID)
- return review, nil
+ return nil
}