summaryrefslogtreecommitdiff
path: root/app/finders/pipelines_finder.rb
diff options
context:
space:
mode:
authorShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-02-21 17:20:50 +0900
committerShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-03 02:11:50 +0900
commite9d94451959e4717e0ba4ca882b5a54437efbee1 (patch)
tree9eae86aa74b50ecdff6771260fa4721deda9c2dd /app/finders/pipelines_finder.rb
parent9fd1a35fa944cc27a88bc504fed3a8b65eb193dd (diff)
downloadgitlab-ce-e9d94451959e4717e0ba4ca882b5a54437efbee1.tar.gz
- Add new parameters for Pipeline API
- Expand PipelinesFinder functions
Diffstat (limited to 'app/finders/pipelines_finder.rb')
-rw-r--r--app/finders/pipelines_finder.rb108
1 files changed, 88 insertions, 20 deletions
diff --git a/app/finders/pipelines_finder.rb b/app/finders/pipelines_finder.rb
index a9172f6767f..5a5416d00cc 100644
--- a/app/finders/pipelines_finder.rb
+++ b/app/finders/pipelines_finder.rb
@@ -1,29 +1,21 @@
class PipelinesFinder
- attr_reader :project, :pipelines
+ attr_reader :project, :pipelines, :params
- def initialize(project)
+ def initialize(project, params = {})
@project = project
@pipelines = project.pipelines
+ @params = params
end
- def execute(scope: nil)
- scoped_pipelines =
- case scope
- when 'running'
- pipelines.running
- when 'pending'
- pipelines.pending
- when 'finished'
- pipelines.finished
- when 'branches'
- from_ids(ids_for_ref(branches))
- when 'tags'
- from_ids(ids_for_ref(tags))
- else
- pipelines
- end
-
- scoped_pipelines.order(id: :desc)
+ def execute
+ items = pipelines
+ items = by_scope(items)
+ items = by_status(items)
+ items = by_ref(items)
+ items = by_user(items)
+ items = by_duration(items)
+ items = by_yaml_error(items)
+ order_and_sort(items)
end
private
@@ -43,4 +35,80 @@ class PipelinesFinder
def tags
project.repository.tag_names
end
+
+ def by_scope(items)
+ case params[:scope]
+ when 'running'
+ items.running
+ when 'pending'
+ items.pending
+ when 'finished'
+ items.finished
+ when 'branches'
+ from_ids(ids_for_ref(branches))
+ when 'tags'
+ from_ids(ids_for_ref(tags))
+ else
+ items
+ end
+ end
+
+ def by_status(items)
+ case params[:status]
+ when 'running'
+ items.running
+ when 'pending'
+ items.pending
+ when 'success'
+ items.success
+ when 'failed'
+ items.failed
+ when 'canceled'
+ items.canceled
+ when 'skipped'
+ items.skipped
+ else
+ items
+ end
+ end
+
+ def by_ref(items)
+ if params[:ref].present?
+ items.where(ref: params[:ref])
+ else
+ items
+ end
+ end
+
+ def by_user(items)
+ if params[:user_id].present?
+ items.where(user_id: params[:user_id])
+ else
+ items
+ end
+ end
+
+ def by_duration(items)
+ if params[:duration].present?
+ items.where("duration > ?", params[:duration])
+ else
+ items
+ end
+ end
+
+ def by_yaml_error(items)
+ if params[:yaml_error].present? && params[:yaml_error]
+ items.where("yaml_errors IS NOT NULL")
+ else
+ items
+ end
+ end
+
+ def order_and_sort(items)
+ if params[:order_by].present? && params[:sort].present?
+ items.order("#{params[:order_by]} #{params[:sort]}")
+ else
+ items.order(id: :desc)
+ end
+ end
end