summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@gitlab.com>2017-03-14 13:35:46 +0100
committerBob Van Landuyt <bob@gitlab.com>2017-03-16 12:31:27 +0100
commita33fbb3c83bb1663fa63ce42ced54926f050b8dc (patch)
tree93129c624b3370856e1df2df3cc8a40010934717
parent4b249d522c0077113745225fe945d8629c58fa34 (diff)
downloadgitlab-ce-a33fbb3c83bb1663fa63ce42ced54926f050b8dc.tar.gz
Render cached pipeline status on project dashboard
-rw-r--r--app/helpers/ci_status_helper.rb14
-rw-r--r--app/models/project.rb4
-rw-r--r--app/views/shared/projects/_project.html.haml6
-rw-r--r--spec/models/project_spec.rb11
4 files changed, 32 insertions, 3 deletions
diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb
index a7cdca9ba2e..a91d19dc347 100644
--- a/app/helpers/ci_status_helper.rb
+++ b/app/helpers/ci_status_helper.rb
@@ -59,6 +59,20 @@ module CiStatusHelper
custom_icon(icon_name)
end
+ def render_project_pipeline_status(pipeline_status, tooltip_placement: 'auto left')
+ project = pipeline_status.project
+ path = pipelines_namespace_project_commit_path(
+ project.namespace,
+ project,
+ pipeline_status.sha)
+
+ render_status_with_link(
+ 'commit',
+ pipeline_status.status,
+ path,
+ tooltip_placement: tooltip_placement)
+ end
+
def render_commit_status(commit, ref: nil, tooltip_placement: 'auto left')
project = commit.project
path = pipelines_namespace_project_commit_path(
diff --git a/app/models/project.rb b/app/models/project.rb
index 8c2dadf4659..2ffaaac93f3 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1209,6 +1209,10 @@ class Project < ActiveRecord::Base
end
end
+ def pipeline_status
+ @pipeline_status ||= Ci::PipelineStatus.load_for_project(self)
+ end
+
def mark_import_as_failed(error_message)
original_errors = errors.dup
sanitized_message = Gitlab::UrlSanitizer.sanitize(error_message)
diff --git a/app/views/shared/projects/_project.html.haml b/app/views/shared/projects/_project.html.haml
index 7e9fb7bb4d3..d1af6fe8d8d 100644
--- a/app/views/shared/projects/_project.html.haml
+++ b/app/views/shared/projects/_project.html.haml
@@ -7,16 +7,16 @@
- show_last_commit_as_description = false unless local_assigns[:show_last_commit_as_description] == true && project.commit
- css_class += " no-description" if project.description.blank? && !show_last_commit_as_description
- cache_key = [project.namespace, project, controller.controller_name, controller.action_name, current_application_settings, 'v2.3']
-- cache_key.push(project.commit&.sha, project.commit&.status)
+- cache_key.push(project.pipeline_status) if project.pipeline_status.has_status?
%li.project-row{ class: css_class }
= cache(cache_key) do
.controls
- if project.archived
%span.label.label-warning archived
- - if project.commit.try(:status)
+ - if project.pipeline_status.has_status?
%span
- = render_commit_status(project.commit)
+ = render_project_pipeline_status(project.pipeline_status)
- if forks
%span
= icon('code-fork')
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index e120e21af06..ff1defcd32d 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -1916,4 +1916,15 @@ describe Project, models: true do
end
end
end
+
+ describe '#pipeline_status' do
+ let(:project) { create(:project) }
+ it 'builds a pipeline status' do
+ expect(project.pipeline_status).to be_a(Ci::PipelineStatus)
+ end
+
+ it 'hase a loaded pipeline status' do
+ expect(project.pipeline_status).to be_loaded
+ end
+ end
end