47b3038434
Partially addresses #47424.
33 lines
571 B
Ruby
33 lines
571 B
Ruby
# frozen_string_literal: true
|
|
|
|
class BranchesFinder
|
|
def initialize(repository, params = {})
|
|
@repository = repository
|
|
@params = params
|
|
end
|
|
|
|
def execute
|
|
branches = @repository.branches_sorted_by(sort)
|
|
filter_by_name(branches)
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :repository, :params
|
|
|
|
def search
|
|
@params[:search].presence
|
|
end
|
|
|
|
def sort
|
|
@params[:sort].presence || 'name'
|
|
end
|
|
|
|
def filter_by_name(branches)
|
|
if search
|
|
branches.select { |branch| branch.name.upcase.include?(search.upcase) }
|
|
else
|
|
branches
|
|
end
|
|
end
|
|
end
|