Skip to content
Snippets Groups Projects
Commit 55a0cbc0 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg Committed by Z.J. van de Weg
Browse files

Ability to use the ref when fetching the commit status

parent 0f6a1260
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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')
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
- 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"
Loading
Loading
Loading
Loading
@@ -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')
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment