diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-04-24 15:13:26 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2017-04-24 15:13:26 +0000 |
commit | 0affdb85b1c84d2664da634b5dea86c1be5e8c6a (patch) | |
tree | ef98102098908374bb6b5fef3c0358846e592b30 | |
parent | 8e6dabb0118a8245f42974f9e92fe53ccb1c43f2 (diff) | |
parent | ee40ec7ddbfb8b1dfdeec615bae34e5e977c5165 (diff) | |
download | gitlab-ce-0affdb85b1c84d2664da634b5dea86c1be5e8c6a.tar.gz |
Merge branch 'fix/gb/fix-incorrect-commit-status-badge-text' into 'master'
Fix incorrect commit status text on main project page
See merge request !10863
-rw-r--r-- | app/helpers/ci_status_helper.rb | 25 | ||||
-rw-r--r-- | app/views/projects/_last_commit.html.haml | 3 | ||||
-rw-r--r-- | changelogs/unreleased/fix-gb-fix-incorrect-commit-status-badge-text.yml | 4 | ||||
-rw-r--r-- | spec/helpers/ci_status_helper_spec.rb | 47 | ||||
-rw-r--r-- | spec/views/projects/_last_commit.html.haml_spec.rb | 22 | ||||
-rw-r--r-- | spec/views/projects/commit/_commit_box.html.haml_spec.rb | 34 |
6 files changed, 114 insertions, 21 deletions
diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index 2de9e0de310..32b1e7822af 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -1,10 +1,16 @@ +## +# DEPRECATED +# +# These helpers are deprecated in favor of detailed CI/CD statuses. +# +# See 'detailed_status?` method and `Gitlab::Ci::Status` module. +# module CiStatusHelper def ci_status_path(pipeline) project = pipeline.project namespace_project_pipeline_path(project.namespace, project, pipeline) end - # Is used by Commit and Merge Request Widget def ci_label_for_status(status) if detailed_status?(status) return status.label @@ -22,6 +28,23 @@ module CiStatusHelper end end + def ci_text_for_status(status) + if detailed_status?(status) + return status.text + end + + case status + when 'success' + 'passed' + when 'success_with_warnings' + 'passed' + when 'manual' + 'blocked' + else + status + end + end + def ci_status_for_statuseable(subject) status = subject.try(:status) || 'not found' status.humanize diff --git a/app/views/projects/_last_commit.html.haml b/app/views/projects/_last_commit.html.haml index e1fea8ccf3d..df3b1c75508 100644 --- a/app/views/projects/_last_commit.html.haml +++ b/app/views/projects/_last_commit.html.haml @@ -1,10 +1,9 @@ - - ref = local_assigns.fetch(:ref) - status = commit.status(ref) - if status = link_to pipelines_namespace_project_commit_path(commit.project.namespace, commit.project, commit), class: "ci-status ci-#{status}" do = ci_icon_for_status(status) - = ci_label_for_status(status) + = ci_text_for_status(status) = link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit_short_id" = link_to_gfm commit.title, namespace_project_commit_path(project.namespace, project, commit), class: "commit-row-message" diff --git a/changelogs/unreleased/fix-gb-fix-incorrect-commit-status-badge-text.yml b/changelogs/unreleased/fix-gb-fix-incorrect-commit-status-badge-text.yml new file mode 100644 index 00000000000..abe047af06f --- /dev/null +++ b/changelogs/unreleased/fix-gb-fix-incorrect-commit-status-badge-text.yml @@ -0,0 +1,4 @@ +--- +title: Fix lastest commit status text on main project page +merge_request: 10863 +author: diff --git a/spec/helpers/ci_status_helper_spec.rb b/spec/helpers/ci_status_helper_spec.rb index c795fe5a2a3..3dc13001056 100644 --- a/spec/helpers/ci_status_helper_spec.rb +++ b/spec/helpers/ci_status_helper_spec.rb @@ -6,25 +6,54 @@ describe CiStatusHelper do let(:success_commit) { double("Ci::Pipeline", status: 'success') } let(:failed_commit) { double("Ci::Pipeline", status: 'failed') } - describe 'ci_icon_for_status' do + describe '#ci_icon_for_status' do it 'renders to correct svg on success' do - expect(helper).to receive(:render).with('shared/icons/icon_status_success.svg', anything) + expect(helper).to receive(:render) + .with('shared/icons/icon_status_success.svg', anything) + helper.ci_icon_for_status(success_commit.status) end + it 'renders the correct svg on failure' do - expect(helper).to receive(:render).with('shared/icons/icon_status_failed.svg', anything) + expect(helper).to receive(:render) + .with('shared/icons/icon_status_failed.svg', anything) + helper.ci_icon_for_status(failed_commit.status) end end + describe '#ci_text_for_status' do + context 'when status is manual' do + it 'changes the status to blocked' do + expect(helper.ci_text_for_status('manual')) + .to eq 'blocked' + end + end + + context 'when status is success' do + it 'changes the status to passed' do + expect(helper.ci_text_for_status('success')) + .to eq 'passed' + end + end + + context 'when status is something else' do + it 'returns status unchanged' do + expect(helper.ci_text_for_status('some-status')) + .to eq 'some-status' + end + end + end + describe "#pipeline_status_cache_key" do + let(:pipeline_status) do + Gitlab::Cache::Ci::ProjectPipelineStatus + .new(build(:project), sha: '123abc', status: 'success') + end + it "builds a cache key for pipeline status" do - pipeline_status = Gitlab::Cache::Ci::ProjectPipelineStatus.new( - build(:project), - sha: "123abc", - status: "success" - ) - expect(helper.pipeline_status_cache_key(pipeline_status)).to eq("pipeline-status/123abc-success") + expect(helper.pipeline_status_cache_key(pipeline_status)) + .to eq("pipeline-status/123abc-success") end end end diff --git a/spec/views/projects/_last_commit.html.haml_spec.rb b/spec/views/projects/_last_commit.html.haml_spec.rb new file mode 100644 index 00000000000..eea1695b171 --- /dev/null +++ b/spec/views/projects/_last_commit.html.haml_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe 'projects/_last_commit', :view do + let(:project) { create(:project, :repository) } + + context 'when there is a pipeline present for the commit' do + context 'when pipeline is blocked' do + let!(:pipeline) do + create(:ci_pipeline, :blocked, project: project, + sha: project.commit.id) + end + + it 'shows correct pipeline badge' do + render 'projects/last_commit', commit: project.commit, + project: project, + ref: :master + + expect(rendered).to have_text "blocked #{project.commit.short_id}" + end + end + end +end diff --git a/spec/views/projects/commit/_commit_box.html.haml_spec.rb b/spec/views/projects/commit/_commit_box.html.haml_spec.rb index cec87dcecc8..ab120929c6c 100644 --- a/spec/views/projects/commit/_commit_box.html.haml_spec.rb +++ b/spec/views/projects/commit/_commit_box.html.haml_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' -describe 'projects/commit/_commit_box.html.haml' do - include Devise::Test::ControllerHelpers - +describe 'projects/commit/_commit_box.html.haml', :view do let(:user) { create(:user) } let(:project) { create(:project, :repository) } @@ -18,14 +16,32 @@ describe 'projects/commit/_commit_box.html.haml' do expect(rendered).to have_text("#{Commit.truncate_sha(project.commit.sha)}") end - it 'shows the last pipeline that ran for the commit' do - create(:ci_pipeline, project: project, sha: project.commit.id, status: 'success') - create(:ci_pipeline, project: project, sha: project.commit.id, status: 'canceled') - third_pipeline = create(:ci_pipeline, project: project, sha: project.commit.id, status: 'failed') + context 'when there is a pipeline present' do + context 'when there are multiple pipelines for a commit' do + it 'shows the last pipeline' do + create(:ci_pipeline, project: project, sha: project.commit.id, status: 'success') + create(:ci_pipeline, project: project, sha: project.commit.id, status: 'canceled') + third_pipeline = create(:ci_pipeline, project: project, sha: project.commit.id, status: 'failed') - render + render + + expect(rendered).to have_text("Pipeline ##{third_pipeline.id} failed") + end + end - expect(rendered).to have_text("Pipeline ##{third_pipeline.id} failed") + context 'when pipeline for the commit is blocked' do + let!(:pipeline) do + create(:ci_pipeline, :blocked, project: project, + sha: project.commit.id) + end + + it 'shows correct pipeline description' do + render + + expect(rendered).to have_text "Pipeline ##{pipeline.id} " \ + 'waiting for manual action' + end + end end context 'viewing a commit' do |