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-11-28 10:50:44 -05:00
|
|
|
refs = project.protected_branches.select(:name)
|
|
|
|
|
|
|
|
self.matching(ref_name, protected_refs: refs).present?
|
2017-04-03 13:59:58 -04:00
|
|
|
end
|
2017-04-03 14:28:54 -04:00
|
|
|
|
|
|
|
def self.default_branch_protected?
|
2018-02-02 13:39:55 -05:00
|
|
|
Gitlab::CurrentSettings.default_branch_protection == Gitlab::Access::PROTECTION_FULL ||
|
|
|
|
Gitlab::CurrentSettings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE
|
2017-04-03 14:28:54 -04:00
|
|
|
end
|
2012-02-15 15:02:33 -05:00
|
|
|
end
|