summaryrefslogtreecommitdiff
path: root/app/models/protected_branch.rb
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2017-04-03 18:59:58 +0100
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2017-04-03 19:19:54 +0100
commitbf3cc824e4ce6cf49a82210eaaf1cca06f7fd281 (patch)
tree04d422fe8b68079ef604348ffe96b1f2b72285ff /app/models/protected_branch.rb
parentb8c7bef5c092152ea85d1840e587cfc04293e1d7 (diff)
downloadgitlab-ce-bf3cc824e4ce6cf49a82210eaaf1cca06f7fd281.tar.gz
Moved Project#protected_branch? to ProtectedBranch, similar for tags
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