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