summaryrefslogtreecommitdiff
path: root/app/finders/branches_finder.rb
blob: 8001c70a9b2badf9c9c773bf3c87ccf932d5449d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

class BranchesFinder < GitRefsFinder
  def initialize(repository, params = {})
    super(repository, params)
  end

  def execute
    branches = repository.branches_sorted_by(sort)
    branches = by_search(branches)
    branches = by_names(branches)
    branches
  end

  private

  def names
    @params[:names].presence
  end

  def by_names(branches)
    return branches unless names

    branch_names = names.to_set
    branches.select do |branch|
      branch_names.include?(branch.name)
    end
  end
end