Commit d865aeda authored by Kamil Trzcinski's avatar Kamil Trzcinski

Introduce `Ci::Stage`, right now this is artificial object that is build dynamically.

parent fa1105b1
......@@ -100,34 +100,24 @@ module Ci
where.not(duration: nil).sum(:duration)
end
def stages_query
statuses.group('stage').select(:stage)
.order('max(stage_idx)')
def stages_count
statuses.select(:stage).distinct.count
end
def stages
self.stages_query.pluck(:stage)
end
def stages_with_statuses
status_sql = statuses.latest.where('stage=sg.stage').status_sql
stages_with_statuses = CommitStatus.from(self.stages_query, :sg).
stages_query = statuses.group('stage').select(:stage)
.order('max(stage_idx)')
stages_with_statuses = CommitStatus.from(stages_query, :sg).
pluck('sg.stage', status_sql)
stages_with_statuses.map do |stage|
OpenStruct.new(
name: stage.first,
status: stage.last,
pipeline: self
)
Ci::Stage.new(self, stage.first, status: stage.last)
end
end
def stages_with_latest_statuses
statuses.latest.includes(project: :namespace).order(:stage_idx).group_by(&:stage)
end
def artifacts
builds.latest.with_artifacts_not_expired
end
......
module Ci
class Stage < ActiveRecord::Base
include ActiveModel::Model
attr_reader :pipeline, :name
def initialize(pipeline, name: name, status: status = nil)
@pipeline, @name, @status = pipeline, name, status
end
def status
@status ||= statuses.latest.status
end
def statuses
pipeline.statuses.where(stage: stage)
end
def builds
pipeline.builds.where(stage: stage)
end
end
end
......@@ -41,8 +41,8 @@ class CommitStatus < ActiveRecord::Base
where("#{quoted_when} <> ? OR status <> ?", 'on_failure', 'skipped')
end
scope :latest_ci_stages, -> { latest.ordered.includes(project: :namespace) }
scope :retried_ci_stages, -> { retried.ordered.includes(project: :namespace) }
scope :latest_ordered, -> { latest.ordered.includes(project: :namespace) }
scope :retried_ordered, -> { retried.ordered.includes(project: :namespace) }
state_machine :status do
event :enqueue do
......@@ -117,11 +117,6 @@ class CommitStatus < ActiveRecord::Base
name.gsub(/\d+[\s:\/\\]+\d+\s*/, '').strip
end
def self.stages
# We group by stage name, but order stages by theirs' index
unscoped.from(all, :sg).group('stage').order('max(stage_idx)', 'stage').select('sg.stage')
end
def failed_but_allowed?
allow_failure? && (failed? || canceled?)
end
......
......@@ -133,7 +133,7 @@
%tr.success-message
%td{style: "font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;color:#333333;font-size:15px;font-weight:400;line-height:1.4;padding:15px 5px;text-align:center;"}
- build_count = @pipeline.statuses.latest.size
- stage_count = @pipeline.stages.size
- stage_count = @pipeline.stages_count
Pipeline
%a{href: pipeline_url(@pipeline), style: "color:#3777b0;text-decoration:none;"}
= "\##{@pipeline.id}"
......
......@@ -16,7 +16,7 @@ Commit Author: <%= commit.author_name %>
<% end -%>
<% build_count = @pipeline.statuses.latest.size -%>
<% stage_count = @pipeline.stages.size -%>
<% stage_count = @pipeline.stages_count -%>
Pipeline #<%= @pipeline.id %> ( <%= pipeline_url(@pipeline) %> ) successfully completed <%= build_count %> <%= 'build'.pluralize(build_count) %> in <%= stage_count %> <%= 'stage'.pluralize(stage_count) %>.
You're receiving this email because of your account on <%= Gitlab.config.gitlab.host %>.
......
......@@ -111,7 +111,7 @@
%span.label.label-primary
= tag
- if @build.pipeline.stages.many?
- if @build.pipeline.stages_count.many?
.dropdown.build-dropdown
.title Stage
%button.dropdown-menu-toggle{type: 'button', 'data-toggle' => 'dropdown'}
......
%tr
%th{colspan: 10}
%strong
%a{name: stage}
- status = statuses.latest.status
%span{class: "ci-status-link ci-status-icon-#{status}"}
= ci_icon_for_status(status)
- if stage
&nbsp;
= stage.titleize
= render statuses.latest_ci_stages, coverage: @project.build_coverage_enabled?, stage: false, ref: false, pipeline_link: false, allow_retry: true
= render statuses.retried_ci_stages, coverage: @project.build_coverage_enabled?, stage: false, ref: false, pipeline_link: false, retried: true
%tr
%td{colspan: 10}
&nbsp;
......@@ -27,16 +27,15 @@
.row-content-block.build-content.middle-block.pipeline-graph.hidden
.pipeline-visualization
%ul.stage-column-list
- stages = pipeline.stages_with_latest_statuses
- stages.each do |stage, statuses|
- pipeline.stages.each do |stage|
%li.stage-column
.stage-name
%a{name: stage}
- if stage
= stage.titleize
%a{name: stage.name}
- if stage.name
= stage.name.titleize
.builds-container
%ul
= render "projects/commit/pipeline_stage", statuses: statuses
= render "projects/commit/pipeline_stage", statuses: stage.statuses
- if pipeline.yaml_errors.present?
......@@ -62,5 +61,4 @@
- if pipeline.project.build_coverage_enabled?
%th Coverage
%th
- pipeline.stages.each do |stage|
= render 'projects/commit/ci_stage', stage: stage, statuses: pipeline.statuses.relevant.where(stage: stage)
= render pipeline.stages
......@@ -15,13 +15,12 @@
.build-content.middle-block.pipeline-graph
.pipeline-visualization
%ul.stage-column-list
- stages = pipeline.stages_with_latest_statuses
- stages.each do |stage, statuses|
- pipeline.stages.each do |stage|
%li.stage-column
.stage-name
%a{name: stage}
- if stage
= stage.titleize
%a{name: stage.name}
- if stage.name
= stage.name.titleize
.builds-container
%ul
= render "projects/commit/pipeline_stage", statuses: statuses
......@@ -50,5 +49,4 @@
- if pipeline.project.build_coverage_enabled?
%th Coverage
%th
- pipeline.statuses.relevant.stages.each do |stage|
= render 'projects/commit/ci_stage', stage: stage, statuses: pipeline.statuses.relevant.where(stage: stage)
= render pipeline.stages
......@@ -37,7 +37,6 @@
%span CI Lint
%div.content-list.pipelines
- stages = @pipelines.stages
- if @pipelines.blank?
%div
.nothing-here-block No pipelines to show
......
%tr
%th{colspan: 10}
%strong
%a{name: subject.name}
%span{class: "ci-status-link ci-status-icon-#{subject.status}"}
= ci_icon_for_status(subject.status)
- if subject.name
&nbsp;
= subject.name.titleize
= render subject.statuses.latest_ordered, coverage: @project.build_coverage_enabled?, stage: false, ref: false, pipeline_link: false, allow_retry: true
= render subject.statuses.retried_ordered, coverage: @project.build_coverage_enabled?, stage: false, ref: false, pipeline_link: false, retried: true
%tr
%td{colspan: 10}
&nbsp;
......@@ -22,7 +22,7 @@ module Gitlab
sha: pipeline.sha,
before_sha: pipeline.before_sha,
status: pipeline.status,
stages: pipeline.stages,
stages: pipeline.stages.map(&:name),
created_at: pipeline.created_at,
finished_at: pipeline.finished_at,
duration: pipeline.duration
......
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