summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-09-23 11:41:24 +0000
committerDouwe Maan <douwe@gitlab.com>2015-09-23 11:41:24 +0000
commite63b64de34a8f00fe1b77afe79dc240cdd654806 (patch)
treeba29f91edfdfcb48e6ffab42fe3ed815362d1a3e
parent486a6479258c993ec1690d20acd0983ee102b967 (diff)
parent3b6915d8910296296676e32129138c50bb1b0c5c (diff)
downloadgitlab-ce-e63b64de34a8f00fe1b77afe79dc240cdd654806.tar.gz
Merge branch 'commits-page-ci-status' into 'master'
Commits page CI status Show CI status for each commit row on pages like: Commits, Merge request (commits tab), Compare etc ![Screenshot_2015-09-23_12.34.50](https://gitlab.com/gitlab-org/gitlab-ce/uploads/d40d6a69f76128e32d3a0cb641b3495b/Screenshot_2015-09-23_12.34.50.png) Fixes #2632 See merge request !1402
-rw-r--r--CHANGELOG2
-rw-r--r--app/helpers/ci_status_helper.rb34
-rw-r--r--app/helpers/commits_helper.rb2
-rw-r--r--app/models/project.rb4
-rw-r--r--app/views/projects/commits/_commit.html.haml10
-rw-r--r--spec/helpers/ci_status_helper_spec.rb18
-rw-r--r--spec/models/project_spec.rb10
7 files changed, 77 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 5d28897425c..80998016563 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,7 +1,7 @@
Please view this file on the master branch, on stable branches it's out of date.
v 8.1.0 (unreleased)
- -
+ - Show CI status on all pages where commits list is rendered
v 8.0.1
- Improve CI migration procedure and documentation
diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb
new file mode 100644
index 00000000000..18c30ddb281
--- /dev/null
+++ b/app/helpers/ci_status_helper.rb
@@ -0,0 +1,34 @@
+module CiStatusHelper
+ def ci_status_path(ci_commit)
+ ci_project_ref_commits_path(ci_commit.project, ci_commit.ref, ci_commit)
+ end
+
+ def ci_status_icon(ci_commit)
+ icon_name =
+ case ci_commit.status
+ when 'success'
+ 'check'
+ when 'failed'
+ 'close'
+ when 'running', 'pending'
+ 'clock-o'
+ else
+ 'circle'
+ end
+
+ icon(icon_name)
+ end
+
+ def ci_status_color(ci_commit)
+ case ci_commit.status
+ when 'success'
+ 'green'
+ when 'failed'
+ 'red'
+ when 'running', 'pending'
+ 'yellow'
+ else
+ 'gray'
+ end
+ end
+end
diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb
index d13d80be293..9df20c9fce5 100644
--- a/app/helpers/commits_helper.rb
+++ b/app/helpers/commits_helper.rb
@@ -135,7 +135,7 @@ module CommitsHelper
# size: size of the avatar image in px
def commit_person_link(commit, options = {})
user = commit.send(options[:source])
-
+
source_name = clean(commit.send "#{options[:source]}_name".to_sym)
source_email = clean(commit.send "#{options[:source]}_email".to_sym)
diff --git a/app/models/project.rb b/app/models/project.rb
index 1a5c1c978c9..72120885105 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -735,4 +735,8 @@ class Project < ActiveRecord::Base
errors.add(:base, 'Failed create wiki')
false
end
+
+ def ci_commit(sha)
+ gitlab_ci_project.commits.find_by(sha: sha) if gitlab_ci?
+ end
end
diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml
index 74f8d8b15cf..efad4cb1473 100644
--- a/app/views/projects/commits/_commit.html.haml
+++ b/app/views/projects/commits/_commit.html.haml
@@ -4,7 +4,11 @@
- notes = commit.notes
- note_count = notes.user.count
-= cache [project.id, commit.id, note_count] do
+- ci_commit = project.ci_commit(commit.sha)
+- cache_key = [project.id, commit.id, note_count]
+- cache_key.push(ci_commit.status) if ci_commit
+
+= cache(cache_key) do
%li.commit.js-toggle-container
.commit-row-title
%strong.str-truncated
@@ -13,6 +17,10 @@
%a.text-expander.js-toggle-button ...
.pull-right
+ - if ci_commit
+ = link_to ci_status_path(ci_commit), class: "c#{ci_status_color(ci_commit)}" do
+ = ci_status_icon(ci_commit)
+ &nbsp;
= link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit_short_id"
.notes_count
diff --git a/spec/helpers/ci_status_helper_spec.rb b/spec/helpers/ci_status_helper_spec.rb
new file mode 100644
index 00000000000..7fc53eb1472
--- /dev/null
+++ b/spec/helpers/ci_status_helper_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe CiStatusHelper do
+ include IconsHelper
+
+ let(:success_commit) { double("Ci::Commit", status: 'success') }
+ let(:failed_commit) { double("Ci::Commit", status: 'failed') }
+
+ describe 'ci_status_color' do
+ it { expect(ci_status_icon(success_commit)).to include('fa-check') }
+ it { expect(ci_status_icon(failed_commit)).to include('fa-close') }
+ end
+
+ describe 'ci_status_color' do
+ it { expect(ci_status_color(success_commit)).to eq('green') }
+ it { expect(ci_status_color(failed_commit)).to eq('red') }
+ end
+end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 2fcbd5ae108..ba57e31f7fe 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -401,4 +401,14 @@ describe Project do
it { should eq "http://localhost#{avatar_path}" }
end
end
+
+ describe :ci_commit do
+ let(:project) { create :project }
+ let(:ci_project) { create :ci_project, gl_project: project }
+ let(:commit) { create :ci_commit, project: ci_project }
+
+ before { project.create_gitlab_ci_service(active: true) }
+
+ it { expect(project.ci_commit(commit.sha)).to eq(commit) }
+ end
end