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