debian-mirror-gitlab/app/finders/branches_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.3 KiB
Ruby
Raw Normal View History

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)
2023-03-17 16:20:25 +05:30
if gitaly_pagination && names.blank? && search.blank? && regex.blank?
2020-07-28 23:09:34 +05:30
repository.branches_sorted_by(sort, pagination_params)
else
branches = repository.branches_sorted_by(sort)
branches = by_search(branches)
2023-03-17 16:20:25 +05:30
branches = by_regex(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
2021-11-11 11:23:49 +05:30
def total
repository.branch_count
end
2016-08-24 12:49:21 +05:30
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
2023-03-17 16:20:25 +05:30
def regex
@params[:regex].to_s.presence
end
strong_memoize_attr :regex
2020-07-28 23:09:34 +05:30
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
2023-03-17 16:20:25 +05:30
def by_regex(branches)
return branches unless regex
branch_filter = ::Gitlab::UntrustedRegexp.new(regex)
branches.select do |branch|
branch_filter.match?(branch.name)
end
end
2016-08-24 12:49:21 +05:30
end