From 5d3fdd121279c758f247a76e020799aa5e548feb Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Mon, 15 Jan 2024 08:20:01 +0100 Subject: 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 --- models/git/protected_branch.go | 1 + models/issues/pull.go | 2 +- models/migrations/v1_22/v284.go | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 models/migrations/v1_22/v284.go (limited to 'models') 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)) +} -- cgit v1.2.3