Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/protected_branches_finder.rb')
-rw-r--r--app/finders/protected_branches_finder.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/app/finders/protected_branches_finder.rb b/app/finders/protected_branches_finder.rb
new file mode 100644
index 00000000000..68e8d2a9f54
--- /dev/null
+++ b/app/finders/protected_branches_finder.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+# ProtectedBranchesFinder
+#
+# Used to filter protected branches by set of params
+#
+# Arguments:
+# project - which project to scope to
+# params:
+# search: string
+class ProtectedBranchesFinder
+ LIMIT = 100
+
+ attr_accessor :project, :params
+
+ def initialize(project, params = {})
+ @project = project
+ @params = params
+ end
+
+ def execute
+ protected_branches = project.limited_protected_branches(LIMIT)
+ protected_branches = by_name(protected_branches)
+
+ protected_branches
+ end
+
+ private
+
+ def by_name(protected_branches)
+ return protected_branches unless params[:search].present?
+
+ protected_branches.by_name(params[:search])
+ end
+end