Commit 182064b6 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'show-status-from-branch' into 'master'

Show pipeline status from branch and commit than only commit

Closes #23615

See merge request !7034
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 9c66b78c
...@@ -192,9 +192,10 @@ class ApplicationController < ActionController::Base ...@@ -192,9 +192,10 @@ class ApplicationController < ActionController::Base
end end
# JSON for infinite scroll via Pager object # JSON for infinite scroll via Pager object
def pager_json(partial, count) def pager_json(partial, count, locals = {})
html = render_to_string( html = render_to_string(
partial, partial,
locals: locals,
layout: false, layout: false,
formats: [:html] formats: [:html]
) )
......
...@@ -26,8 +26,15 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -26,8 +26,15 @@ class Projects::CommitsController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json { pager_json("projects/commits/_commits", @commits.size) }
format.atom { render layout: false } format.atom { render layout: false }
format.json do
pager_json(
'projects/commits/_commits',
@commits.size,
project: @project,
ref: @ref)
end
end end
end end
end end
...@@ -352,13 +352,23 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -352,13 +352,23 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def branch_from def branch_from
# This is always source # This is always source
@source_project = @merge_request.nil? ? @project : @merge_request.source_project @source_project = @merge_request.nil? ? @project : @merge_request.source_project
@commit = @repository.commit(params[:ref]) if params[:ref].present?
if params[:ref].present?
@ref = params[:ref]
@commit = @repository.commit(@ref)
end
render layout: false render layout: false
end end
def branch_to def branch_to
@target_project = selected_target_project @target_project = selected_target_project
@commit = @target_project.commit(params[:ref]) if params[:ref].present?
if params[:ref].present?
@ref = params[:ref]
@commit = @target_project.commit(@ref)
end
render layout: false render layout: false
end end
......
...@@ -54,10 +54,18 @@ module CiStatusHelper ...@@ -54,10 +54,18 @@ module CiStatusHelper
custom_icon(icon_name) custom_icon(icon_name)
end end
def render_commit_status(commit, tooltip_placement: 'auto left') def render_commit_status(commit, ref: nil, tooltip_placement: 'auto left')
project = commit.project project = commit.project
path = pipelines_namespace_project_commit_path(project.namespace, project, commit) path = pipelines_namespace_project_commit_path(
render_status_with_link('commit', commit.status, path, tooltip_placement: tooltip_placement) project.namespace,
project,
commit)
render_status_with_link(
'commit',
commit.status(ref),
path,
tooltip_placement: tooltip_placement)
end end
def render_pipeline_status(pipeline, tooltip_placement: 'auto left') def render_pipeline_status(pipeline, tooltip_placement: 'auto left')
......
...@@ -25,9 +25,11 @@ module CommitsHelper ...@@ -25,9 +25,11 @@ module CommitsHelper
end end
end end
def commit_to_html(commit, project, inline = true) def commit_to_html(commit, ref, project)
template = inline ? "inline_commit" : "commit" render 'projects/commits/commit',
render "projects/commits/#{template}", commit: commit, project: project unless commit.nil? commit: commit,
ref: ref,
project: project
end end
# Breadcrumb links for a Project and, if applicable, a tree path # Breadcrumb links for a Project and, if applicable, a tree path
......
...@@ -226,12 +226,19 @@ class Commit ...@@ -226,12 +226,19 @@ class Commit
end end
def pipelines def pipelines
@pipeline ||= project.pipelines.where(sha: sha) project.pipelines.where(sha: sha)
end end
def status def status(ref = nil)
return @status if defined?(@status) @statuses ||= {}
@status ||= pipelines.status
if @statuses.key?(ref)
@statuses[ref]
elsif ref
@statuses[ref] = pipelines.where(ref: ref).status
else
@statuses[ref] = pipelines.status
end
end end
def revert_branch_name def revert_branch_name
......
- if commit.status - ref = local_assigns.fetch(:ref)
= link_to builds_namespace_project_commit_path(commit.project.namespace, commit.project, commit), class: "ci-status ci-#{commit.status}" do - status = commit.status(ref)
= ci_icon_for_status(commit.status) - if status
= ci_label_for_status(commit.status) = link_to builds_namespace_project_commit_path(commit.project.namespace, commit.project, commit), class: "ci-status ci-#{status}" do
= ci_icon_for_status(status)
= ci_label_for_status(status)
= link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit_short_id" = 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" = link_to_gfm commit.title, namespace_project_commit_path(project.namespace, project, commit), class: "commit-row-message"
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
%ul.blob-commit-info.hidden-xs %ul.blob-commit-info.hidden-xs
- blob_commit = @repository.last_commit_for_path(@commit.id, blob.path) - blob_commit = @repository.last_commit_for_path(@commit.id, blob.path)
= render blob_commit, project: @project = render blob_commit, project: @project, ref: @ref
%div#blob-content-holder.blob-content-holder %div#blob-content-holder.blob-content-holder
%article.file-holder %article.file-holder
......
- ref = local_assigns.fetch(:ref)
- if @note_counts - if @note_counts
- note_count = @note_counts.fetch(commit.id, 0) - note_count = @note_counts.fetch(commit.id, 0)
- else - else
...@@ -18,15 +19,15 @@ ...@@ -18,15 +19,15 @@
%span.commit-row-message.visible-xs-inline %span.commit-row-message.visible-xs-inline
&middot; &middot;
= commit.short_id = commit.short_id
- if commit.status - if commit.status(ref)
.visible-xs-inline .visible-xs-inline
= render_commit_status(commit) = render_commit_status(commit, ref: ref)
- if commit.description? - if commit.description?
%a.text-expander.hidden-xs.js-toggle-button ... %a.text-expander.hidden-xs.js-toggle-button ...
.commit-actions.hidden-xs .commit-actions.hidden-xs
- if commit.status - if commit.status(ref)
= render_commit_status(commit) = render_commit_status(commit, ref: ref)
= clipboard_button(clipboard_text: commit.id) = clipboard_button(clipboard_text: commit.id)
= link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit-short-id btn btn-transparent" = link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit-short-id btn btn-transparent"
= link_to_browse_code(project, commit) = link_to_browse_code(project, commit)
......
...@@ -11,4 +11,4 @@ ...@@ -11,4 +11,4 @@
%li.warning-row.unstyled %li.warning-row.unstyled
#{number_with_delimiter(hidden)} additional commits have been omitted to prevent performance issues. #{number_with_delimiter(hidden)} additional commits have been omitted to prevent performance issues.
- else - else
%ul.content-list= render commits, project: @project %ul.content-list= render commits, project: @project, ref: @ref
- unless defined?(project) - ref = local_assigns.fetch(:ref)
- project = @project
- commits, hidden = limited_commits(@commits) - commits, hidden = limited_commits(@commits)
- commits.chunk { |c| c.committed_date.in_time_zone.to_date }.each do |day, commits| - commits.chunk { |c| c.committed_date.in_time_zone.to_date }.each do |day, commits|
%li.commit-header= "#{day.strftime('%d %b, %Y')} #{pluralize(commits.count, 'commit')}" %li.commit-header= "#{day.strftime('%d %b, %Y')} #{pluralize(commits.count, 'commit')}"
%li.commits-row %li.commits-row
%ul.list-unstyled.commit-list %ul.list-unstyled.commit-list
= render commits, project: project = render commits, project: project, ref: ref
- if hidden > 0 - if hidden > 0
%li.alert.alert-warning %li.alert.alert-warning
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
%div{id: dom_id(@project)} %div{id: dom_id(@project)}
%ol#commits-list.list-unstyled.content_list %ol#commits-list.list-unstyled.content_list
= render "commits", project: @project = render 'commits', project: @project, ref: @ref
= spinner = spinner
:javascript :javascript
......
= commit_to_html(@commit, @source_project, false) - if @commit
= commit_to_html(@commit, @ref, @source_project)
= commit_to_html(@commit, @target_project, false) - if @commit
= commit_to_html(@commit, @ref, @target_project)
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
Most recent commits displayed first Most recent commits displayed first
%ol#commits-list.list-unstyled %ol#commits-list.list-unstyled
= render "projects/commits/commits", project: @merge_request.project = render "projects/commits/commits", project: @merge_request.source_project, ref: @merge_request.source_branch
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
= render 'shared/notifications/button', notification_setting: @notification_setting = render 'shared/notifications/button', notification_setting: @notification_setting
- if @repository.commit - if @repository.commit
.project-last-commit{ class: container_class } .project-last-commit{ class: container_class }
= render 'projects/last_commit', commit: @repository.commit, project: @project = render 'projects/last_commit', commit: @repository.commit, ref: current_ref, project: @project
%div{ class: container_class } %div{ class: container_class }
- if @project.archived? - if @project.archived?
......
---
title: Fix showing pipeline status for a given commit from correct branch
merge_request: 7034
author:
...@@ -12,11 +12,15 @@ describe 'Commits' do ...@@ -12,11 +12,15 @@ describe 'Commits' do
end end
let!(:pipeline) do let!(:pipeline) do
FactoryGirl.create :ci_pipeline, project: project, sha: project.commit.sha create(:ci_pipeline,
project: project,
ref: project.default_branch,
sha: project.commit.sha,
status: :success)
end end
context 'commit status is Generic Commit Status' do context 'commit status is Generic Commit Status' do
let!(:status) { FactoryGirl.create :generic_commit_status, pipeline: pipeline } let!(:status) { create(:generic_commit_status, pipeline: pipeline) }
before do before do
project.team << [@user, :reporter] project.team << [@user, :reporter]
...@@ -39,7 +43,7 @@ describe 'Commits' do ...@@ -39,7 +43,7 @@ describe 'Commits' do
end end
context 'commit status is Ci Build' do context 'commit status is Ci Build' do
let!(:build) { FactoryGirl.create :ci_build, pipeline: pipeline } let!(:build) { create(:ci_build, pipeline: pipeline) }
let(:artifacts_file) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') } let(:artifacts_file) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
context 'when logged as developer' do context 'when logged as developer' do
...@@ -48,13 +52,22 @@ describe 'Commits' do ...@@ -48,13 +52,22 @@ describe 'Commits' do
end end
describe 'Project commits' do describe 'Project commits' do
let!(:pipeline_from_other_branch) do
create(:ci_pipeline,
project: project,
ref: 'fix',
sha: project.commit.sha,
status: :failed)
end
before do before do
visit namespace_project_commits_path(project.namespace, project, :master) visit namespace_project_commits_path(project.namespace, project, :master)
end end
it 'shows build status' do it 'shows correct build status from default branch' do
page.within("//li[@id='commit-#{pipeline.short_sha}']") do page.within("//li[@id='commit-#{pipeline.short_sha}']") do
expect(page).to have_css(".ci-status-link") expect(page).to have_css('.ci-status-link')
expect(page).to have_css('.ci-status-icon-success')
end end
end end
end end
......
...@@ -205,12 +205,53 @@ eos ...@@ -205,12 +205,53 @@ eos
end end
end end
describe '#ci_commits' do
# TODO: kamil
end
describe '#status' do describe '#status' do
# TODO: kamil context 'without arguments for compound status' do
shared_examples 'giving the status from pipeline' do
it do
expect(commit.status).to eq(Ci::Pipeline.status)
end
end
context 'with pipelines' do
let!(:pipeline) do
create(:ci_empty_pipeline, project: project, sha: commit.sha)
end
it_behaves_like 'giving the status from pipeline'
end
context 'without pipelines' do
it_behaves_like 'giving the status from pipeline'
end
end
context 'when a particular ref is specified' do
let!(:pipeline_from_master) do
create(:ci_empty_pipeline,
project: project,
sha: commit.sha,
ref: 'master',
status: 'failed')
end
let!(:pipeline_from_fix) do
create(:ci_empty_pipeline,
project: project,
sha: commit.sha,
ref: 'fix',
status: 'success')
end
it 'gives pipelines from a particular branch' do
expect(commit.status('master')).to eq(pipeline_from_master.status)
expect(commit.status('fix')).to eq(pipeline_from_fix.status)
end
it 'gives compound status if ref is nil' do
expect(commit.status(nil)).to eq(commit.status)
end
end
end end
describe '#participants' do describe '#participants' do
......
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