2020-02-06 16:08:48 -05:00
|
|
|
# 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
|
|
|
|
|
|
|
|
attr_accessor :project, :params
|
|
|
|
|
|
|
|
def initialize(project, params = {})
|
|
|
|
@project = project
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
protected_branches = project.limited_protected_branches(LIMIT)
|
2021-04-19 11:09:08 -04:00
|
|
|
by_name(protected_branches)
|
2020-02-06 16:08:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def by_name(protected_branches)
|
|
|
|
return protected_branches unless params[:search].present?
|
|
|
|
|
|
|
|
protected_branches.by_name(params[:search])
|
|
|
|
end
|
|
|
|
end
|