2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
class BranchesFinder < GitRefsFinder
|
2018-03-27 19:54:05 +05:30
|
|
|
def initialize(repository, params = {})
|
2019-12-26 22:10:19 +05:30
|
|
|
super(repository, params)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
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-29 21:17:54 +05:30
|
|
|
by_names(branches)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def names
|
|
|
|
@params[:names].presence
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
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-09-30 21:07:59 +05:30
|
|
|
def by_names(branches)
|
|
|
|
return branches unless names
|
|
|
|
|
|
|
|
branch_names = names.to_set
|
2019-10-12 21:52:04 +05:30
|
|
|
branches.select do |branch|
|
2019-09-30 21:07:59 +05:30
|
|
|
branch_names.include?(branch.name)
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|