2012-02-15 15:02:33 -05:00
|
|
|
class ProtectedBranch < ActiveRecord::Base
|
2013-03-21 15:01:14 -04:00
|
|
|
include Gitlab::ShellAdapter
|
2017-04-03 10:17:24 -04:00
|
|
|
include ProtectedRef
|
2012-02-15 15:02:33 -05:00
|
|
|
|
2017-05-05 11:59:31 -04:00
|
|
|
protected_ref_access_levels :merge, :push
|
2017-04-03 13:59:58 -04:00
|
|
|
|
|
|
|
# Check if branch name is marked as protected in the system
|
|
|
|
def self.protected?(project, ref_name)
|
2017-04-03 14:28:54 -04:00
|
|
|
return true if project.empty_repo? && default_branch_protected?
|
2017-04-03 13:59:58 -04:00
|
|
|
|
2017-04-03 14:47:08 -04:00
|
|
|
self.matching(ref_name, protected_refs: project.protected_branches).present?
|
2017-04-03 13:59:58 -04:00
|
|
|
end
|
2017-04-03 14:28:54 -04:00
|
|
|
|
|
|
|
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
|
2012-02-15 15:02:33 -05:00
|
|
|
end
|