diff options
author | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-08-29 18:02:08 +0200 |
---|---|---|
committer | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-09-07 15:38:03 +0200 |
commit | 3152477114ed95d2ca5b5a27487c4f392f7486fa (patch) | |
tree | 76f12a95dbb8b25a4a8e37d1e3ee17880329b3fc /app/finders | |
parent | a83c5ff48f74c718bd4d0f9b5746502e2ebaff27 (diff) | |
download | gitlab-ce-3152477114ed95d2ca5b5a27487c4f392f7486fa.tar.gz |
Use PipelinesFinder in Pipelines API
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/pipelines_finder.rb | 32 |
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 |