summaryrefslogtreecommitdiff
path: root/app/models/protected_branch.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/protected_branch.rb')
-rw-r--r--app/models/protected_branch.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb
index a0dbcf80c3d..eca8d5e0f7d 100644
--- a/app/models/protected_branch.rb
+++ b/app/models/protected_branch.rb
@@ -10,4 +10,12 @@ class ProtectedBranch < ActiveRecord::Base
accepts_nested_attributes_for :push_access_levels
accepts_nested_attributes_for :merge_access_levels
+
+ # Check if branch name is marked as protected in the system
+ def self.protected?(project, ref_name)
+ return true if project.empty_and_default_branch_protected?
+
+ protected_refs = project.protected_branches_array
+ self.matching(ref_name, protected_refs: protected_refs).present?
+ end
end