Commit b4ef158a authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent 7cdb238a
......@@ -54,15 +54,18 @@ module CiStatusHelper
custom_icon(icon_name)
end
def render_commit_ref_status(commit, ref = nil, **args)
pipeline = commit.pipelines_for(ref).last
render_pipeline_status(pipeline, **args)
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)
path = pipelines_namespace_project_commit_path(
project.namespace,
project,
commit)
render_status_with_link(
'commit',
commit.status_for(ref),
path,
tooltip_placement: tooltip_placement)
end
def render_pipeline_status(pipeline, tooltip_placement: 'auto left')
......
......@@ -51,12 +51,14 @@ class Commit
end
attr_accessor :raw
attr_reader :statuses
def initialize(raw_commit, project)
raise "Nil as raw commit passed" unless raw_commit
@raw = raw_commit
@project = project
@statuses = {}
end
def id
......@@ -225,17 +227,22 @@ class Commit
)
end
def pipelines_for(ref)
project.pipelines.where(sha: sha, ref: ref)
end
def pipelines
@pipeline ||= project.pipelines.where(sha: sha)
project.pipelines.where(sha: sha)
end
def status
return @status if defined?(@status)
@status ||= pipelines.status
status_for(nil)
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
def revert_branch_name
......
......@@ -20,13 +20,13 @@
= commit.short_id
- if commit.status
.visible-xs-inline
= render_commit_ref_status(commit, ref)
= render_commit_status(commit, ref: ref)
- if commit.description?
%a.text-expander.hidden-xs.js-toggle-button ...
.commit-actions.hidden-xs
- if commit.status
= render_commit_ref_status(commit, ref)
= render_commit_status(commit, ref: ref)
= 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_browse_code(project, commit)
......
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