From 353d426e4e68006ba8cea90e2f6ad4e8956cb6a9 Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Thu, 24 Sep 2015 14:00:23 +0200
Subject: [PATCH] Show CI status on Your projects page and Starred projects
 page

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
---
 CHANGELOG                                        |  1 +
 app/assets/stylesheets/pages/projects.scss       |  8 +++++++-
 app/views/dashboard/projects/_projects.html.haml |  2 +-
 app/views/shared/projects/_list.html.haml        |  3 ++-
 app/views/shared/projects/_project.html.haml     | 13 +++++++++++--
 features/dashboard/dashboard.feature             |  4 +++-
 features/steps/dashboard/dashboard.rb            |  4 ++++
 features/steps/project/graph.rb                  |  4 ----
 features/steps/shared/project.rb                 | 10 ++++++++++
 9 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 9c9554eb00f..48d2b646339 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,7 @@ v 8.1.0 (unreleased)
   - Fix cases where Markdown did not render links in activity feed (Stan Hu)
   - Add first and last to pagination (Zeger-Jan van de Weg)
   - Show CI status on commit page
+  - Show CI status on Your projects page and Starred projects page
 
 v 8.0.2 (unreleased)
   - Skip check_initd_configured_correctly on omnibus installs
diff --git a/app/assets/stylesheets/pages/projects.scss b/app/assets/stylesheets/pages/projects.scss
index a986fafff07..8d75f3aad49 100644
--- a/app/assets/stylesheets/pages/projects.scss
+++ b/app/assets/stylesheets/pages/projects.scss
@@ -297,9 +297,15 @@ pre.light-well {
       color: #4c4e54;
     }
 
-    .pull-right.light {
+    .project-controls {
+      float: right;
+      color: $gl-gray;
       line-height: 45px;
       color: #7f8fa4;
+
+      a:hover {
+        text-decoration: none;
+      }
     }
 
     .project-description {
diff --git a/app/views/dashboard/projects/_projects.html.haml b/app/views/dashboard/projects/_projects.html.haml
index ef9b9ce756a..c8c315c73d8 100644
--- a/app/views/dashboard/projects/_projects.html.haml
+++ b/app/views/dashboard/projects/_projects.html.haml
@@ -7,4 +7,4 @@
           = link_to new_project_path, class: 'btn btn-success' do
             New project
 
-  = render 'shared/projects/list', projects: @projects
+  = render 'shared/projects/list', projects: @projects, ci: true
diff --git a/app/views/shared/projects/_list.html.haml b/app/views/shared/projects/_list.html.haml
index 330b0626d63..16e1d8421de 100644
--- a/app/views/shared/projects/_list.html.haml
+++ b/app/views/shared/projects/_list.html.haml
@@ -1,12 +1,13 @@
 - projects_limit = 20 unless local_assigns[:projects_limit]
 - avatar = true unless local_assigns[:avatar] == false
 - stars = true unless local_assigns[:stars] == false
+- ci = false unless local_assigns[:ci] == true
 
 %ul.projects-list
   - projects.each_with_index do |project, i|
     - css_class = (i >= projects_limit) ? 'hide' : nil
     = render "shared/projects/project", project: project,
-      avatar: avatar, stars: stars, css_class: css_class
+      avatar: avatar, stars: stars, css_class: css_class, ci: ci
 
   - if projects.size > projects_limit
     %li.bottom.center
diff --git a/app/views/shared/projects/_project.html.haml b/app/views/shared/projects/_project.html.haml
index 5318c6011f4..1c529c91c51 100644
--- a/app/views/shared/projects/_project.html.haml
+++ b/app/views/shared/projects/_project.html.haml
@@ -1,9 +1,10 @@
 - avatar = true unless local_assigns[:avatar] == false
 - stars = true unless local_assigns[:stars] == false
+- ci = false unless local_assigns[:ci] == true
 - css_class = '' unless local_assigns[:css_class]
 - css_class += " no-description" unless project.description.present?
 %li.project-row{ class: css_class }
-  = cache [project.namespace, project, controller.controller_name, controller.action_name, 'v2.1'] do
+  = cache [project.namespace, project, controller.controller_name, controller.action_name, 'v2.2'] do
     = link_to project_path(project), class: dom_class(project) do
       - if avatar
         .dash-project-avatar
@@ -15,8 +16,16 @@
             \/
         %span.project-name.filter-title
           = project.name
+
+    .project-controls
+      - if ci && !project.empty_repo?
+        - if ci_commit = project.ci_commit(project.commit.sha)
+          = link_to ci_status_path(ci_commit), class: "c#{ci_status_color(ci_commit)}",
+            title: "Build status: #{ci_commit.status}", data: {toggle: 'tooltip', placement: 'left'} do
+            = ci_status_icon(ci_commit)
+          &nbsp;
       - if stars
-        %span.pull-right.light
+        %span
           %i.fa.fa-star
           = project.star_count
     - if project.description.present?
diff --git a/features/dashboard/dashboard.feature b/features/dashboard/dashboard.feature
index 392d4235eff..b667b587c5b 100644
--- a/features/dashboard/dashboard.feature
+++ b/features/dashboard/dashboard.feature
@@ -4,12 +4,14 @@ Feature: Dashboard
     Given I sign in as a user
     And I own project "Shop"
     And project "Shop" has push event
+    And project "Shop" has CI enabled
+    And project "Shop" has CI build
     And I visit dashboard page
 
-  @javascript
   Scenario: I should see projects list
     Then I should see "New Project" link
     Then I should see "Shop" project link
+    Then I should see "Shop" project CI status
 
   @javascript
   Scenario: I should see activity list
diff --git a/features/steps/dashboard/dashboard.rb b/features/steps/dashboard/dashboard.rb
index cb3a80cac29..f0fbd8a826a 100644
--- a/features/steps/dashboard/dashboard.rb
+++ b/features/steps/dashboard/dashboard.rb
@@ -11,6 +11,10 @@ class Spinach::Features::Dashboard < Spinach::FeatureSteps
     expect(page).to have_link "Shop"
   end
 
+  step 'I should see "Shop" project CI status' do
+    expect(page).to have_link "Build status: skipped"
+  end
+
   step 'I should see last push widget' do
     expect(page).to have_content "You pushed to fix"
     expect(page).to have_link "Create Merge Request"
diff --git a/features/steps/project/graph.rb b/features/steps/project/graph.rb
index 9f9d099961d..9453d636445 100644
--- a/features/steps/project/graph.rb
+++ b/features/steps/project/graph.rb
@@ -23,10 +23,6 @@ class Spinach::Features::ProjectGraph < Spinach::FeatureSteps
     visit ci_namespace_project_graph_path(project.namespace, project, 'master')
   end
 
-  step 'project "Shop" has CI enabled' do
-    project.enable_ci(@user)
-  end
-
   step 'page should have CI graphs' do
     expect(page).to have_content 'Overall'
     expect(page).to have_content 'Builds chart for last week'
diff --git a/features/steps/shared/project.rb b/features/steps/shared/project.rb
index a9cf426852e..fa841f67510 100644
--- a/features/steps/shared/project.rb
+++ b/features/steps/shared/project.rb
@@ -196,4 +196,14 @@ module SharedProject
     create(:label, project: project, title: 'feature')
     create(:label, project: project, title: 'enhancement')
   end
+
+  step 'project "Shop" has CI enabled' do
+    project = Project.find_by(name: "Shop")
+    project.enable_ci(@user)
+  end
+
+  step 'project "Shop" has CI build' do
+    project = Project.find_by(name: "Shop")
+    create :ci_commit, project: project.gitlab_ci_project, sha: project.commit.sha
+  end
 end
-- 
GitLab