aboutsummaryrefslogtreecommitdiffstats
path: root/services/pull/review.go
diff options
context:
space:
mode:
authorDavid Svantesson <davidsvantesson@gmail.com>2020-01-09 02:47:45 +0100
committerzeripath <art27@cantab.net>2020-01-09 01:47:45 +0000
commit25531c71a78b98af91f25d5e6eaa362e5fc54a86 (patch)
tree3dc44abba51f55f66020755d31fa909a9c56990e /services/pull/review.go
parent5b2d9333f1d06a15f11906b39c4867cc5d1c9448 (diff)
downloadgitea-25531c71a78b98af91f25d5e6eaa362e5fc54a86.tar.gz
gitea-25531c71a78b98af91f25d5e6eaa362e5fc54a86.zip
Mark PR reviews as stale at push and allow to dismiss stale approvals (#9532)
Fix #5997. If a push causes the patch/diff of a PR towards target branch to change, all existing reviews for the PR will be set and shown as stale. New branch protection option to dismiss stale approvals are added. To show that a review is not based on the latest PR changes, an hourglass is shown
Diffstat (limited to 'services/pull/review.go')
-rw-r--r--services/pull/review.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/services/pull/review.go b/services/pull/review.go
index 5b453e87f4..2bc8240230 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -18,7 +18,7 @@ import (
)
// CreateCodeComment creates a comment on the code line
-func CreateCodeComment(doer *models.User, issue *models.Issue, line int64, content string, treePath string, isReview bool, replyReviewID int64) (*models.Comment, error) {
+func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models.Issue, line int64, content string, treePath string, isReview bool, replyReviewID int64, latestCommitID string) (*models.Comment, error) {
var (
existsReview bool
@@ -73,6 +73,7 @@ func CreateCodeComment(doer *models.User, issue *models.Issue, line int64, conte
Reviewer: doer,
Issue: issue,
Official: false,
+ CommitID: latestCommitID,
})
if err != nil {
return nil, err
@@ -94,7 +95,7 @@ func CreateCodeComment(doer *models.User, issue *models.Issue, line int64, conte
if !isReview && !existsReview {
// Submit the review we've just created so the comment shows up in the issue view
- if _, _, err = SubmitReview(doer, issue, models.ReviewTypeComment, ""); err != nil {
+ if _, _, err = SubmitReview(doer, gitRepo, issue, models.ReviewTypeComment, "", latestCommitID); err != nil {
return nil, err
}
}
@@ -159,16 +160,36 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
}
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
-func SubmitReview(doer *models.User, issue *models.Issue, reviewType models.ReviewType, content string) (*models.Review, *models.Comment, error) {
- review, comm, err := models.SubmitReview(doer, issue, reviewType, content)
+func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issue, reviewType models.ReviewType, content, commitID string) (*models.Review, *models.Comment, error) {
+ pr, err := issue.GetPullRequest()
if err != nil {
return nil, nil, err
}
- pr, err := issue.GetPullRequest()
+ var stale bool
+ if reviewType != models.ReviewTypeApprove && reviewType != models.ReviewTypeReject {
+ stale = false
+ } else {
+ headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
+ if err != nil {
+ return nil, nil, err
+ }
+
+ if headCommitID == commitID {
+ stale = false
+ } else {
+ stale, err = checkIfPRContentChanged(pr, commitID, headCommitID)
+ if err != nil {
+ return nil, nil, err
+ }
+ }
+ }
+
+ review, comm, err := models.SubmitReview(doer, issue, reviewType, content, commitID, stale)
if err != nil {
return nil, nil, err
}
+
notification.NotifyPullRequestReview(pr, review, comm)
return review, comm, nil