protected_branch.rb 652 Bytes
Newer Older
1
class ProtectedBranch < ActiveRecord::Base
2
  include Gitlab::ShellAdapter
3
  include ProtectedRef
4

5
  protected_ref_access_levels :merge, :push
6 7 8

  # Check if branch name is marked as protected in the system
  def self.protected?(project, ref_name)
9
    return true if project.empty_repo? && default_branch_protected?
10

11
    self.matching(ref_name, protected_refs: project.protected_branches).present?
12
  end
13 14 15 16 17

  def self.default_branch_protected?
    current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_FULL ||
      current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE
  end
18
end