summaryrefslogtreecommitdiff
path: root/app/finders/pipelines_finder.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/pipelines_finder.rb')
-rw-r--r--app/finders/pipelines_finder.rb32
1 files changed, 18 insertions, 14 deletions
diff --git a/app/finders/pipelines_finder.rb b/app/finders/pipelines_finder.rb
index 641fbf838f1..32aea75486d 100644
--- a/app/finders/pipelines_finder.rb
+++ b/app/finders/pipelines_finder.rb
@@ -1,30 +1,34 @@
class PipelinesFinder
- attr_reader :project
+ attr_reader :project, :pipelines
def initialize(project)
@project = project
+ @pipelines = project.pipelines
end
- def execute(pipelines, scope)
- case scope
- when 'running'
- pipelines.running_or_pending
- when 'branches'
- from_ids(pipelines, ids_for_ref(pipelines, branches))
- when 'tags'
- from_ids(pipelines, ids_for_ref(pipelines, tags))
- else
- pipelines
- end
+ def execute(scope: nil)
+ scoped_pipelines =
+ case scope
+ when 'running'
+ pipelines.running_or_pending
+ when 'branches'
+ from_ids(ids_for_ref(branches))
+ when 'tags'
+ from_ids(ids_for_ref(tags))
+ else
+ pipelines
+ end
+
+ scoped_pipelines.order(id: :desc)
end
private
- def ids_for_ref(pipelines, refs)
+ def ids_for_ref(refs)
pipelines.where(ref: refs).group(:ref).select('max(id)')
end
- def from_ids(pipelines, ids)
+ def from_ids(ids)
pipelines.unscoped.where(id: ids)
end