BigW Consortium Gitlab

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

5 6
  extend Gitlab::CurrentSettings

7
  protected_ref_access_levels :merge, :push
8 9 10

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

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

  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
20
end