2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-03 12:10:58 -04:00
|
|
|
class ProtectableDropdown
|
2017-08-10 12:39:26 -04:00
|
|
|
REF_TYPES = %i[branches tags].freeze
|
|
|
|
|
2017-04-03 12:10:58 -04:00
|
|
|
def initialize(project, ref_type)
|
2017-08-10 12:39:26 -04:00
|
|
|
raise ArgumentError, "invalid ref type `#{ref_type}`" unless ref_type.in?(REF_TYPES)
|
|
|
|
|
2017-04-03 12:10:58 -04:00
|
|
|
@project = project
|
|
|
|
@ref_type = ref_type
|
|
|
|
end
|
|
|
|
|
|
|
|
# Tags/branches which are yet to be individually protected
|
|
|
|
def protectable_ref_names
|
2017-04-05 13:59:46 -04:00
|
|
|
@protectable_ref_names ||= ref_names - non_wildcard_protected_ref_names
|
2017-04-03 12:10:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def hash
|
|
|
|
protectable_ref_names.map { |ref_name| { text: ref_name, id: ref_name, title: ref_name } }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def refs
|
2017-08-10 12:39:26 -04:00
|
|
|
@project.repository.public_send(@ref_type) # rubocop:disable GitlabSecurity/PublicSend
|
2017-04-03 12:10:58 -04:00
|
|
|
end
|
|
|
|
|
2017-04-05 13:59:46 -04:00
|
|
|
def ref_names
|
|
|
|
refs.map(&:name)
|
|
|
|
end
|
|
|
|
|
2017-04-03 12:10:58 -04:00
|
|
|
def protections
|
2017-08-10 12:39:26 -04:00
|
|
|
@project.public_send("protected_#{@ref_type}") # rubocop:disable GitlabSecurity/PublicSend
|
2017-04-03 12:10:58 -04:00
|
|
|
end
|
2017-04-05 13:59:46 -04:00
|
|
|
|
|
|
|
def non_wildcard_protected_ref_names
|
|
|
|
protections.reject(&:wildcard?).map(&:name)
|
|
|
|
end
|
2017-04-03 12:10:58 -04:00
|
|
|
end
|