summaryrefslogtreecommitdiffstats
path: root/modules
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 /modules
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 'modules')
-rw-r--r--modules/auth/repo_form.go19
-rw-r--r--modules/git/repo_compare.go6
-rw-r--r--modules/repofiles/update.go4
3 files changed, 19 insertions, 10 deletions
diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go
index c87549af92..28615ebbc4 100644
--- a/modules/auth/repo_form.go
+++ b/modules/auth/repo_form.go
@@ -172,6 +172,7 @@ type ProtectBranchForm struct {
ApprovalsWhitelistUsers string
ApprovalsWhitelistTeams string
BlockOnRejectedReviews bool
+ DismissStaleApprovals bool
}
// Validate validates the fields
@@ -456,12 +457,13 @@ func (f *MergePullRequestForm) Validate(ctx *macaron.Context, errs binding.Error
// CodeCommentForm form for adding code comments for PRs
type CodeCommentForm struct {
- Content string `binding:"Required"`
- Side string `binding:"Required;In(previous,proposed)"`
- Line int64
- TreePath string `form:"path" binding:"Required"`
- IsReview bool `form:"is_review"`
- Reply int64 `form:"reply"`
+ Content string `binding:"Required"`
+ Side string `binding:"Required;In(previous,proposed)"`
+ Line int64
+ TreePath string `form:"path" binding:"Required"`
+ IsReview bool `form:"is_review"`
+ Reply int64 `form:"reply"`
+ LatestCommitID string
}
// Validate validates the fields
@@ -471,8 +473,9 @@ func (f *CodeCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) bi
// SubmitReviewForm for submitting a finished code review
type SubmitReviewForm struct {
- Content string
- Type string `binding:"Required;In(approve,comment,reject)"`
+ Content string
+ Type string `binding:"Required;In(approve,comment,reject)"`
+ CommitID string
}
// Validate validates the fields
diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go
index 53b8af4bb4..683ac7a7ee 100644
--- a/modules/git/repo_compare.go
+++ b/modules/git/repo_compare.go
@@ -112,3 +112,9 @@ func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
return NewCommand("format-patch", "--binary", "--stdout", base+"..."+head).
RunInDirPipeline(repo.Path, w, nil)
}
+
+// GetDiffFromMergeBase generates and return patch data from merge base to head
+func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) error {
+ return NewCommand("diff", "-p", "--binary", base+"..."+head).
+ RunInDirPipeline(repo.Path, w, nil)
+}
diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go
index 19c3d5b51c..7ad4a4d388 100644
--- a/modules/repofiles/update.go
+++ b/modules/repofiles/update.go
@@ -477,7 +477,7 @@ func PushUpdate(repo *models.Repository, branch string, opts PushUpdateOptions)
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
- go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true)
+ go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true, opts.OldCommitID, opts.NewCommitID)
if err = models.WatchIfAuto(opts.PusherID, repo.ID, true); err != nil {
log.Warn("Fail to perform auto watch on user %v for repo %v: %v", opts.PusherID, repo.ID, err)
@@ -528,7 +528,7 @@ func PushUpdates(repo *models.Repository, optsList []*PushUpdateOptions) error {
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, opts.Branch, pusher.Name)
- go pull_service.AddTestPullRequestTask(pusher, repo.ID, opts.Branch, true)
+ go pull_service.AddTestPullRequestTask(pusher, repo.ID, opts.Branch, true, opts.OldCommitID, opts.NewCommitID)
if err = models.WatchIfAuto(opts.PusherID, repo.ID, true); err != nil {
log.Warn("Fail to perform auto watch on user %v for repo %v: %v", opts.PusherID, repo.ID, err)