diff options
| author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-05-14 14:44:35 -0500 |
|---|---|---|
| committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-05-14 14:45:11 -0500 |
| commit | 8c93b6051fdc7bb59af2e6bf2f5b3a1817a73ceb (patch) | |
| tree | 0bfb05abbd63aa85a67c72595489730649f20a01 | |
| parent | a6b8d36ae933c3f21e7ba2c17864c6d8bf626d25 (diff) | |
| download | gitlab-ce-8c93b6051fdc7bb59af2e6bf2f5b3a1817a73ceb.tar.gz | |
Revert `stages` change
| -rw-r--r-- | app/models/commit_status.rb | 11 | ||||
| -rw-r--r-- | app/views/projects/ci/commits/_commit.html.haml | 3 | ||||
| -rw-r--r-- | spec/models/commit_status_spec.rb | 12 |
3 files changed, 22 insertions, 4 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 213cd20e8d8..6fef1c038e9 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -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? diff --git a/app/views/projects/ci/commits/_commit.html.haml b/app/views/projects/ci/commits/_commit.html.haml index 7f9a3417836..90ac41666d0 100644 --- a/app/views/projects/ci/commits/_commit.html.haml +++ b/app/views/projects/ci/commits/_commit.html.haml @@ -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) diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index ea60894c419..434e58cfd06 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -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 |
