debian-mirror-gitlab/app/finders/pipelines_finder.rb

43 lines
754 B
Ruby
Raw Normal View History

2016-06-02 11:05:42 +05:30
class PipelinesFinder
2016-09-29 09:46:39 +05:30
attr_reader :project, :pipelines
2016-06-02 11:05:42 +05:30
def initialize(project)
@project = project
2016-09-29 09:46:39 +05:30
@pipelines = project.pipelines
2016-06-02 11:05:42 +05:30
end
2016-09-29 09:46:39 +05:30
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)
2016-06-02 11:05:42 +05:30
end
private
2016-09-29 09:46:39 +05:30
def ids_for_ref(refs)
2016-06-02 11:05:42 +05:30
pipelines.where(ref: refs).group(:ref).select('max(id)')
end
2016-09-29 09:46:39 +05:30
def from_ids(ids)
2016-06-02 11:05:42 +05:30
pipelines.unscoped.where(id: ids)
end
def branches
2016-08-24 12:49:21 +05:30
project.repository.branch_names
2016-06-02 11:05:42 +05:30
end
def tags
2016-08-24 12:49:21 +05:30
project.repository.tag_names
2016-06-02 11:05:42 +05:30
end
end