2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# ProtectedBranchesFinder
|
|
|
|
#
|
|
|
|
# Used to filter protected branches by set of params
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# project - which project to scope to
|
|
|
|
# params:
|
|
|
|
# search: string
|
|
|
|
class ProtectedBranchesFinder
|
|
|
|
LIMIT = 100
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
attr_accessor :project_or_group, :params
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def initialize(project_or_group, params = {})
|
|
|
|
@project_or_group = project_or_group
|
2020-03-13 15:44:24 +05:30
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2023-04-23 21:23:45 +05:30
|
|
|
protected_branches = if project_or_group.is_a?(Group)
|
|
|
|
project_or_group.protected_branches
|
|
|
|
else
|
|
|
|
project_or_group.all_protected_branches
|
|
|
|
end
|
|
|
|
|
|
|
|
protected_branches = protected_branches.limit(LIMIT)
|
2021-04-29 21:17:54 +05:30
|
|
|
by_name(protected_branches)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def by_name(protected_branches)
|
|
|
|
return protected_branches unless params[:search].present?
|
|
|
|
|
|
|
|
protected_branches.by_name(params[:search])
|
|
|
|
end
|
|
|
|
end
|