diff options
Diffstat (limited to 'app/models/protected_branch.rb')
-rw-r--r-- | app/models/protected_branch.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb index ad418a47476..cbbdd091feb 100644 --- a/app/models/protected_branch.rb +++ b/app/models/protected_branch.rb @@ -7,6 +7,9 @@ class ProtectedBranch < ApplicationRecord scope :requiring_code_owner_approval, -> { where(code_owner_approval_required: true) } + scope :allowing_force_push, + -> { where(allow_force_push: true) } + protected_ref_access_levels :merge, :push def self.protected_ref_accessible_to?(ref, user, project:, action:, protected_refs: nil) @@ -26,6 +29,12 @@ class ProtectedBranch < ApplicationRecord self.matching(ref_name, protected_refs: protected_refs(project)).present? end + def self.allow_force_push?(project, ref_name) + return false unless ::Feature.enabled?(:allow_force_push_to_protected_branches, project) + + project.protected_branches.allowing_force_push.matching(ref_name).any? + end + def self.any_protected?(project, ref_names) protected_refs(project).any? do |protected_ref| ref_names.any? do |ref_name| |