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

39 lines
697 B
Ruby
Raw Normal View History

2016-06-02 11:05:42 +05:30
class PipelinesFinder
attr_reader :project
def initialize(project)
@project = project
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
end
private
def ids_for_ref(pipelines, refs)
pipelines.where(ref: refs).group(:ref).select('max(id)')
end
def from_ids(pipelines, ids)
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