diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 19:00:14 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 19:00:14 +0000 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /app/finders/branches_finder.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) | |
download | gitlab-ce-05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2.tar.gz |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'app/finders/branches_finder.rb')
-rw-r--r-- | app/finders/branches_finder.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/app/finders/branches_finder.rb b/app/finders/branches_finder.rb index a62d47071d4..dc7b9f6a0ce 100644 --- a/app/finders/branches_finder.rb +++ b/app/finders/branches_finder.rb @@ -6,11 +6,12 @@ class BranchesFinder < GitRefsFinder end def execute(gitaly_pagination: false) - if gitaly_pagination && names.blank? && search.blank? + if gitaly_pagination && names.blank? && search.blank? && regex.blank? repository.branches_sorted_by(sort, pagination_params) else branches = repository.branches_sorted_by(sort) branches = by_search(branches) + branches = by_regex(branches) by_names(branches) end end @@ -29,6 +30,11 @@ class BranchesFinder < GitRefsFinder @params[:per_page].presence end + def regex + @params[:regex].to_s.presence + end + strong_memoize_attr :regex + def page_token "#{Gitlab::Git::BRANCH_REF_PREFIX}#{@params[:page_token]}" if @params[:page_token] end @@ -45,4 +51,14 @@ class BranchesFinder < GitRefsFinder branch_names.include?(branch.name) end end + + 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 end |