Commit 8c93b605 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Revert `stages` change

parent a6b8d36a
......@@ -55,11 +55,16 @@ class CommitStatus < ActiveRecord::Base
def self.stages
# We group by stage name, but order stages by theirs' index
unscoped.where(id: all.ids).group('stage').order('max(stage_idx)', 'stage').pluck('stage')
unscoped.from(all, :sg).group('stage').order('max(stage_idx)', 'stage').pluck('sg.stage')
end
def self.status_for_stage(stage)
where(stage: stage).status
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
def ignored?
......
......@@ -31,9 +31,10 @@
Cant find HEAD commit for this branch
- stages_status = commit.statuses.stages_status
- stages.each do |stage|
%td
- if status = commit.statuses.status_for_stage(stage)
- if status = stages_status[stage]
- tooltip = "#{stage.titleize}: #{status}"
%span.has-tooltip(title="#{tooltip}"){class: "ci-status-icon-#{status}"}
= ci_icon_for_status(status)
......
......@@ -185,5 +185,17 @@ describe CommitStatus, models: true do
is_expected.to eq(%w(build test deploy))
end
end
context 'stages with statuses' do
subject { CommitStatus.where(commit: commit).stages_status }
it 'return list of stages with statuses' do
is_expected.to eq({
'build' => 'failed',
'test' => 'success',
'deploy' => 'running'
})
end
end
end
end
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