aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorJimmy Praet <jimmy.praet@telenet.be>2024-01-15 08:20:01 +0100
committerGitHub <noreply@github.com>2024-01-15 07:20:01 +0000
commit5d3fdd121279c758f247a76e020799aa5e548feb (patch)
treee27b631cfdfd35d673da1130c9639633a1e3bc10 /models
parentce0225c1b87d682f53b87496c8dd6ccee0396f0b (diff)
downloadgitea-5d3fdd121279c758f247a76e020799aa5e548feb.tar.gz
gitea-5d3fdd121279c758f247a76e020799aa5e548feb.zip
Add branch protection setting for ignoring stale approvals (#28498)
Fixes #27114. * In Gitea 1.12 (#9532), a "dismiss stale approvals" branch protection setting was introduced, for ignoring stale reviews when verifying the approval count of a pull request. * In Gitea 1.14 (#12674), the "dismiss review" feature was added. * This caused confusion with users (#25858), as "dismiss" now means 2 different things. * In Gitea 1.20 (#25882), the behavior of the "dismiss stale approvals" branch protection was modified to actually dismiss the stale review. For some users this new behavior of dismissing the stale reviews is not desirable. So this PR reintroduces the old behavior as a new "ignore stale approvals" branch protection setting. --------- Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'models')
-rw-r--r--models/git/protected_branch.go1
-rw-r--r--models/issues/pull.go2
-rw-r--r--models/migrations/v1_22/v284.go14
3 files changed, 16 insertions, 1 deletions
diff --git a/models/git/protected_branch.go b/models/git/protected_branch.go
index 66a4b52b17..e0ff4d1542 100644
--- a/models/git/protected_branch.go
+++ b/models/git/protected_branch.go
@@ -54,6 +54,7 @@ type ProtectedBranch struct {
BlockOnOfficialReviewRequests bool `xorm:"NOT NULL DEFAULT false"`
BlockOnOutdatedBranch bool `xorm:"NOT NULL DEFAULT false"`
DismissStaleApprovals bool `xorm:"NOT NULL DEFAULT false"`
+ IgnoreStaleApprovals bool `xorm:"NOT NULL DEFAULT false"`
RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"`
ProtectedFilePatterns string `xorm:"TEXT"`
UnprotectedFilePatterns string `xorm:"TEXT"`
diff --git a/models/issues/pull.go b/models/issues/pull.go
index 34bea921a0..614ee9a87c 100644
--- a/models/issues/pull.go
+++ b/models/issues/pull.go
@@ -801,7 +801,7 @@ func GetGrantedApprovalsCount(ctx context.Context, protectBranch *git_model.Prot
And("type = ?", ReviewTypeApprove).
And("official = ?", true).
And("dismissed = ?", false)
- if protectBranch.DismissStaleApprovals {
+ if protectBranch.IgnoreStaleApprovals {
sess = sess.And("stale = ?", false)
}
approvals, err := sess.Count(new(Review))
diff --git a/models/migrations/v1_22/v284.go b/models/migrations/v1_22/v284.go
new file mode 100644
index 0000000000..1a4c786964
--- /dev/null
+++ b/models/migrations/v1_22/v284.go
@@ -0,0 +1,14 @@
+// Copyright 2023 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package v1_22 //nolint
+import (
+ "xorm.io/xorm"
+)
+
+func AddIgnoreStaleApprovalsColumnToProtectedBranchTable(x *xorm.Engine) error {
+ type ProtectedBranch struct {
+ IgnoreStaleApprovals bool `xorm:"NOT NULL DEFAULT false"`
+ }
+ return x.Sync(new(ProtectedBranch))
+}