2018-09-11 15:08:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-11-05 07:06:20 -05:00
|
|
|
class BranchesFinder < GitRefsFinder
|
2017-11-15 09:56:36 -05:00
|
|
|
def initialize(repository, params = {})
|
2019-11-05 07:06:20 -05:00
|
|
|
super(repository, params)
|
2016-07-07 12:19:21 -04:00
|
|
|
end
|
|
|
|
|
2020-07-17 05:09:43 -04:00
|
|
|
def execute(gitaly_pagination: false)
|
|
|
|
if gitaly_pagination && names.blank? && search.blank?
|
|
|
|
repository.branches_sorted_by(sort, pagination_params)
|
|
|
|
else
|
|
|
|
branches = repository.branches_sorted_by(sort)
|
|
|
|
branches = by_search(branches)
|
2021-04-19 11:09:08 -04:00
|
|
|
by_names(branches)
|
2020-07-17 05:09:43 -04:00
|
|
|
end
|
2016-07-07 12:19:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-06-18 10:20:11 -04:00
|
|
|
def names
|
|
|
|
@params[:names].presence
|
|
|
|
end
|
|
|
|
|
2020-07-17 05:09:43 -04:00
|
|
|
def per_page
|
|
|
|
@params[:per_page].presence
|
|
|
|
end
|
|
|
|
|
|
|
|
def page_token
|
|
|
|
"#{Gitlab::Git::BRANCH_REF_PREFIX}#{@params[:page_token]}" if @params[:page_token]
|
|
|
|
end
|
|
|
|
|
|
|
|
def pagination_params
|
|
|
|
{ limit: per_page, page_token: page_token }
|
|
|
|
end
|
|
|
|
|
2019-06-18 10:20:11 -04:00
|
|
|
def by_names(branches)
|
|
|
|
return branches unless names
|
|
|
|
|
|
|
|
branch_names = names.to_set
|
2019-08-05 12:07:26 -04:00
|
|
|
branches.select do |branch|
|
2019-06-18 10:20:11 -04:00
|
|
|
branch_names.include?(branch.name)
|
|
|
|
end
|
|
|
|
end
|
2016-07-07 12:19:21 -04:00
|
|
|
end
|