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/branches_finder.rb')
-rw-r--r--app/finders/branches_finder.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/finders/branches_finder.rb b/app/finders/branches_finder.rb
new file mode 100644
index 00000000000..533076585c0
--- /dev/null
+++ b/app/finders/branches_finder.rb
@@ -0,0 +1,31 @@
+class BranchesFinder
+ def initialize(repository, params)
+ @repository = repository
+ @params = params
+ end
+
+ def execute
+ branches = @repository.branches_sorted_by(sort)
+ filter_by_name(branches)
+ end
+
+ private
+
+ attr_reader :repository, :params
+
+ def search
+ @params[:search].presence
+ end
+
+ def sort
+ @params[:sort].presence || 'name'
+ end
+
+ def filter_by_name(branches)
+ if search
+ branches.select { |branch| branch.name.include?(search) }
+ else
+ branches
+ end
+ end
+end