Commit 4e06818d authored by Kamil Trzcinski's avatar Kamil Trzcinski

Support pipelines API

Pass `updated_at` to get only incremental changes since last update
parent 532c0319
...@@ -98,19 +98,38 @@ module Ci ...@@ -98,19 +98,38 @@ module Ci
sha[0...8] sha[0...8]
end end
def self.stages
# We use pluck here due to problems with MySQL which doesn't allow LIMIT/OFFSET in queries
CommitStatus.where(pipeline: pluck(:id)).stages
end
def self.total_duration def self.total_duration
where.not(duration: nil).sum(:duration) where.not(duration: nil).sum(:duration)
end end
def stages
statuses.group('stage').select(:stage)
.order('max(stage_idx)')
end
def stages_with_statuses
status_sql = statuses.latest.where('stage=sg.stage').status_sql
stages_with_statuses = CommitStatus.from(self.stages, :sg).
pluck('sg.stage', status_sql)
stages_with_statuses.map do |stage|
OpenStruct.new(
name: stage.first,
status: stage.last,
pipeline: self
)
end
end
def stages_with_latest_statuses def stages_with_latest_statuses
statuses.latest.includes(project: :namespace).order(:stage_idx).group_by(&:stage) statuses.latest.includes(project: :namespace).order(:stage_idx).group_by(&:stage)
end end
def artifacts
builds.latest.with_artifacts_not_expired
end
def project_id def project_id
project.id project.id
end end
......
...@@ -119,16 +119,7 @@ class CommitStatus < ActiveRecord::Base ...@@ -119,16 +119,7 @@ class CommitStatus < ActiveRecord::Base
def self.stages def self.stages
# We group by stage name, but order stages by theirs' index # We group by stage name, but order stages by theirs' index
unscoped.from(all, :sg).group('stage').order('max(stage_idx)', 'stage').pluck('sg.stage') unscoped.from(all, :sg).group('stage').order('max(stage_idx)', 'stage').select('sg.stage')
end
def self.stages_status
# We execute subquery for each stage to calculate a stage status
statuses = unscoped.from(all, :sg).group('stage').pluck('sg.stage', all.where('stage=sg.stage').status_sql)
statuses.inject({}) do |h, k|
h[k.first] = k.last
h
end
end end
def failed_but_allowed? def failed_but_allowed?
......
...@@ -45,9 +45,10 @@ ...@@ -45,9 +45,10 @@
- stages_status = pipeline.statuses.latest.stages_status - stages_status = pipeline.statuses.latest.stages_status
%td.stage-cell %td.stage-cell
- stages.each do |stage| - pipeline.statuses.latest.stages_status.each do |stage|
- status = stages_status[stage] - name = stage.first
- tooltip = "#{stage.titleize}: #{status || 'not found'}" - status = stage.last
- tooltip = "#{name.titleize}: #{status || 'not found'}"
- if status - if status
.stage-container .stage-container
= link_to namespace_project_pipeline_path(pipeline.project.namespace, pipeline.project, pipeline.id, anchor: stage), class: "has-tooltip ci-status-icon-#{status}", title: tooltip do = link_to namespace_project_pipeline_path(pipeline.project.namespace, pipeline.project, pipeline.id, anchor: stage), class: "has-tooltip ci-status-icon-#{status}", title: tooltip do
......
...@@ -62,5 +62,5 @@ ...@@ -62,5 +62,5 @@
- if pipeline.project.build_coverage_enabled? - if pipeline.project.build_coverage_enabled?
%th Coverage %th Coverage
%th %th
- pipeline.statuses.relevant.stages.each do |stage| - pipeline.stages.each do |stage|
= render 'projects/commit/ci_stage', stage: stage, statuses: pipeline.statuses.relevant.where(stage: stage) = render 'projects/commit/ci_stage', stage: stage, statuses: pipeline.statuses.relevant.where(stage: stage)
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
%th Stages %th Stages
%th %th
%th %th
= render pipelines, commit_sha: true, stage: true, allow_retry: true, stages: pipelines.stages, show_commit: false = render pipelines, commit_sha: true, stage: true, allow_retry: true, show_commit: false
...@@ -51,6 +51,6 @@ ...@@ -51,6 +51,6 @@
%th Stages %th Stages
%th %th
%th.hidden-xs %th.hidden-xs
= render @pipelines, commit_sha: true, stage: true, allow_retry: true, stages: stages = render @pipelines, commit_sha: true, stage: true, allow_retry: true
= paginate @pipelines, theme: 'gitlab' = paginate @pipelines, theme: 'gitlab'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment