summaryrefslogtreecommitdiff
path: root/app/finders/branches_finder.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/branches_finder.rb')
-rw-r--r--app/finders/branches_finder.rb18
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