diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-08-14 23:32:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-14 23:32:19 +0800 |
commit | c021890930bc1f1e52ac538e3eab4c2574513dfa (patch) | |
tree | 60d41ae2b96f562d7d251ed5d76a29a3e142f16f /modules/pull | |
parent | eaa4d4ea98e62ebbc44039d0a01604a464d3ad2a (diff) | |
download | gitea-c021890930bc1f1e52ac538e3eab4c2574513dfa.tar.gz gitea-c021890930bc1f1e52ac538e3eab4c2574513dfa.zip |
move CreateReview to moduels/pull (#7841)
Diffstat (limited to 'modules/pull')
-rw-r--r-- | modules/pull/review.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/modules/pull/review.go b/modules/pull/review.go new file mode 100644 index 0000000000..3fdfaaff84 --- /dev/null +++ b/modules/pull/review.go @@ -0,0 +1,57 @@ +// Copyright 2019 The Gitea Authors. +// All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package pull + +import ( + "code.gitea.io/gitea/models" + api "code.gitea.io/gitea/modules/structs" +) + +// CreateReview creates a new review based on opts +func CreateReview(opts models.CreateReviewOptions) (*models.Review, error) { + review, err := models.CreateReview(opts) + if err != nil { + return nil, err + } + + var reviewHookType models.HookEventType + + switch opts.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 review, nil + } + + pr := opts.Issue.PullRequest + + if err := pr.LoadIssue(); err != nil { + return nil, err + } + + mode, err := models.AccessLevel(opts.Issue.Poster, opts.Issue.Repo) + if err != nil { + return nil, err + } + + if err := models.PrepareWebhooks(opts.Issue.Repo, reviewHookType, &api.PullRequestPayload{ + Action: api.HookIssueSynchronized, + Index: opts.Issue.Index, + PullRequest: pr.APIFormat(), + Repository: opts.Issue.Repo.APIFormat(mode), + Sender: opts.Reviewer.APIFormat(), + }); err != nil { + return nil, err + } + go models.HookQueue.Add(opts.Issue.Repo.ID) + + return review, nil +} |