summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <zegerjan@gitlab.com>2016-10-18 09:40:48 +0200
committerZ.J. van de Weg <git@zjvandeweg.nl>2016-11-01 10:46:16 +0100
commit55a0cbc0835e5387a547dd4430550e71da6fb823 (patch)
treed32d182159d5eaf7661adb7df5cb83ede3f7019e
parent0f6a1260d9eb7443ec3a5a1d61b32be7e8fd5b52 (diff)
downloadgitlab-ce-zj-correct-status-multiple-pipelines.tar.gz
Ability to use the ref when fetching the commit statuszj-correct-status-multiple-pipelines
-rw-r--r--app/helpers/ci_status_helper.rb4
-rw-r--r--app/models/commit.rb9
-rw-r--r--app/views/projects/_last_commit.html.haml9
-rw-r--r--app/views/shared/projects/_project.html.haml2
-rw-r--r--spec/models/commit_spec.rb19
5 files changed, 31 insertions, 12 deletions
diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb
index b7f48630bd4..d368d864d6f 100644
--- a/app/helpers/ci_status_helper.rb
+++ b/app/helpers/ci_status_helper.rb
@@ -54,10 +54,10 @@ module CiStatusHelper
custom_icon(icon_name)
end
- def render_commit_status(commit, tooltip_placement: 'auto left')
+ def render_commit_status(commit, ref: nil, tooltip_placement: 'auto left')
project = commit.project
path = pipelines_namespace_project_commit_path(project.namespace, project, commit)
- render_status_with_link('commit', commit.status, path, tooltip_placement: tooltip_placement)
+ render_status_with_link('commit', commit.status(ref), path, tooltip_placement: tooltip_placement)
end
def render_pipeline_status(pipeline, tooltip_placement: 'auto left')
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 069ea3f77b5..874692000b2 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -233,8 +233,15 @@ class Commit
@pipelines
end
+ # Passing the ref for this method makes sure we filter on commit and ref, so
+ # we can have better results as other pipeline status' won't influence the
+ # one you want
def status(ref = nil)
- pipelines(ref).last.try(:status)
+ if ref && pipelines(ref).any?
+ pipelines(ref).last.status
+ else
+ pipelines.status
+ end
end
def revert_branch_name
diff --git a/app/views/projects/_last_commit.html.haml b/app/views/projects/_last_commit.html.haml
index 630ae7d6140..1c764c28087 100644
--- a/app/views/projects/_last_commit.html.haml
+++ b/app/views/projects/_last_commit.html.haml
@@ -1,7 +1,8 @@
-- if commit.status
- = link_to builds_namespace_project_commit_path(commit.project.namespace, commit.project, commit), class: "ci-status ci-#{commit.status}" do
- = ci_icon_for_status(commit.status)
- = ci_label_for_status(commit.status)
+- commit_status = commit.status(@project.default_branch)
+- if commit_status
+ = link_to builds_namespace_project_commit_path(commit.project.namespace, commit.project, commit), class: "ci-status ci-#{commit_status}" do
+ = ci_icon_for_status(commit_status)
+ = ci_label_for_status(commit_status)
= link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit_short_id"
= link_to_gfm commit.title, namespace_project_commit_path(project.namespace, project, commit), class: "commit-row-message"
diff --git a/app/views/shared/projects/_project.html.haml b/app/views/shared/projects/_project.html.haml
index e8668048703..17cfafe0567 100644
--- a/app/views/shared/projects/_project.html.haml
+++ b/app/views/shared/projects/_project.html.haml
@@ -16,7 +16,7 @@
%span.label.label-warning archived
- if project.commit.try(:status)
%span
- = render_commit_status(project.commit)
+ = render_commit_status(project.commit, ref: project.default_branch)
- if forks
%span
= icon('code-fork')
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 195e9c1277b..132b77d38b2 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -213,11 +213,22 @@ eos
let(:commit) { project.commit }
context 'when the pipeline is available' do
- it 'only uses the last pipeline' do
- create(:ci_pipeline_without_jobs, project: project, status: 'failed', sha: commit.id)
- create(:ci_pipeline_without_jobs, project: project, status: 'success', sha: commit.id)
+ context 'without ref' do
+ it 'only uses the last pipeline' do
+ create(:ci_pipeline_without_jobs, project: project, status: 'failed', sha: commit.id)
+ create(:ci_pipeline_without_jobs, project: project, status: 'success', sha: commit.id)
- expect(commit.status).to eq('success')
+ expect(commit.status).to eq('failed')
+ end
+ end
+
+ context 'with ref' do
+ it 'only uses the last pipeline' do
+ create(:ci_pipeline_without_jobs, project: project, status: 'failed', sha: commit.id)
+ create(:ci_pipeline_without_jobs, project: project, status: 'success', sha: commit.id)
+
+ expect(commit.status('master')).to eq('success')
+ end
end
end