Lin Jen-Shin 2016-10-27 00:48:32 +08:00
parent 7cdb238ac5
commit b4ef158a63
3 changed files with 27 additions and 17 deletions

View File

@ -54,15 +54,18 @@ module CiStatusHelper
custom_icon(icon_name) custom_icon(icon_name)
end end
def render_commit_ref_status(commit, ref = nil, **args) def render_commit_status(commit, ref: nil, tooltip_placement: 'auto left')
pipeline = commit.pipelines_for(ref).last
render_pipeline_status(pipeline, **args)
end
def render_commit_status(commit, 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_for(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')

View File

@ -51,12 +51,14 @@ class Commit
end end
attr_accessor :raw attr_accessor :raw
attr_reader :statuses
def initialize(raw_commit, project) def initialize(raw_commit, project)
raise "Nil as raw commit passed" unless raw_commit raise "Nil as raw commit passed" unless raw_commit
@raw = raw_commit @raw = raw_commit
@project = project @project = project
@statuses = {}
end end
def id def id
@ -225,17 +227,22 @@ class Commit
) )
end end
def pipelines_for(ref)
project.pipelines.where(sha: sha, ref: ref)
end
def pipelines def pipelines
@pipeline ||= project.pipelines.where(sha: sha) project.pipelines.where(sha: sha)
end end
def status def status
return @status if defined?(@status) status_for(nil)
@status ||= pipelines.status end
def status_for(ref)
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

View File

@ -20,13 +20,13 @@
= commit.short_id = commit.short_id
- if commit.status - if commit.status
.visible-xs-inline .visible-xs-inline
= render_commit_ref_status(commit, ref) = 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
= render_commit_ref_status(commit, ref) = 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)