diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-05 12:06:20 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-05 12:06:20 +0000 |
commit | 791785af5540d18eaa97da24f9ff8638e1960b72 (patch) | |
tree | caeb6f08d9cc10a0052dc6851b46653d94c29022 /app/finders/branches_finder.rb | |
parent | a92d6b36c2d2892e8c070efb169f0c06815900ee (diff) | |
download | gitlab-ce-791785af5540d18eaa97da24f9ff8638e1960b72.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders/branches_finder.rb')
-rw-r--r-- | app/finders/branches_finder.rb | 51 |
1 files changed, 2 insertions, 49 deletions
diff --git a/app/finders/branches_finder.rb b/app/finders/branches_finder.rb index 291a24c1405..8001c70a9b2 100644 --- a/app/finders/branches_finder.rb +++ b/app/finders/branches_finder.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -class BranchesFinder +class BranchesFinder < GitRefsFinder def initialize(repository, params = {}) - @repository = repository - @params = params + super(repository, params) end def execute @@ -15,56 +14,10 @@ class BranchesFinder private - attr_reader :repository, :params - def names @params[:names].presence end - def search - @params[:search].presence - end - - def sort - @params[:sort].presence || 'name' - end - - def by_search(branches) - return branches unless search - - case search - when ->(v) { v.starts_with?('^') } - filter_branches_with_prefix(branches, search.slice(1..-1).upcase) - when ->(v) { v.ends_with?('$') } - filter_branches_with_suffix(branches, search.chop.upcase) - else - matches = filter_branches_by_name(branches, search.upcase) - set_exact_match_as_first_result(matches, search) - end - end - - def filter_branches_with_prefix(branches, prefix) - branches.select { |branch| branch.name.upcase.starts_with?(prefix) } - end - - def filter_branches_with_suffix(branches, suffix) - branches.select { |branch| branch.name.upcase.ends_with?(suffix) } - end - - def filter_branches_by_name(branches, term) - branches.select { |branch| branch.name.upcase.include?(term) } - end - - def set_exact_match_as_first_result(matches, term) - exact_match_index = find_exact_match_index(matches, term) - matches.insert(0, matches.delete_at(exact_match_index)) if exact_match_index - matches - end - - def find_exact_match_index(matches, term) - matches.index { |branch| branch.name.casecmp(term) == 0 } - end - def by_names(branches) return branches unless names |