diff options
author | Paul Slaughter <pslaughter@gitlab.com> | 2018-10-03 12:08:00 +0300 |
---|---|---|
committer | Paul Slaughter <pslaughter@gitlab.com> | 2018-10-03 21:18:21 +0300 |
commit | becb86ea4e8032788b151caac004b2635b57c6a4 (patch) | |
tree | fbad0bec9e69fb82d6a72967ccae2812bbd25eb9 | |
parent | 5a286eb7a3a0c395d35c722ce6a067aca47473f2 (diff) |
Add pipeline status to diffs/commit_item
**Notes:**
- Also exposes commit.pipeline_status_path in diffs.json
-rw-r--r-- | app/assets/javascripts/diffs/components/commit_item.vue | 6 | ||||
-rw-r--r-- | app/models/commit.rb | 6 | ||||
-rw-r--r-- | app/serializers/commit_entity.rb | 11 | ||||
-rw-r--r-- | app/serializers/diffs_entity.rb | 4 | ||||
-rw-r--r-- | spec/javascripts/diffs/components/commit_item_spec.js | 17 | ||||
-rw-r--r-- | spec/serializers/commit_entity_spec.rb | 12 |
6 files changed, 53 insertions, 3 deletions
diff --git a/app/assets/javascripts/diffs/components/commit_item.vue b/app/assets/javascripts/diffs/components/commit_item.vue index 4028002febd..993206b2e73 100644 --- a/app/assets/javascripts/diffs/components/commit_item.vue +++ b/app/assets/javascripts/diffs/components/commit_item.vue @@ -5,6 +5,7 @@ import Icon from '~/vue_shared/components/icon.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import CIIcon from '~/vue_shared/components/ci_icon.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; +import CommitPipelineStatus from '~/projects/tree/components/commit_pipeline_status_component.vue'; /** * CommitItem @@ -29,6 +30,7 @@ export default { ClipboardButton, CIIcon, TimeAgoTooltip, + CommitPipelineStatus, }, props: { commit: { @@ -106,6 +108,10 @@ export default { v-if="commit.signatureHtml" v-html="commit.signatureHtml" ></div> + <commit-pipeline-status + v-if="commit.pipelineStatusPath" + :endpoint="commit.pipelineStatusPath" + /> <div class="commit-sha-group"> <div class="label label-monospace" diff --git a/app/models/commit.rb b/app/models/commit.rb index 49c36ad9d3f..a61ed03cf35 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -319,7 +319,11 @@ class Commit def status(ref = nil) return @statuses[ref] if @statuses.key?(ref) - @statuses[ref] = project.pipelines.latest_status_per_commit(id, ref)[id] + @statuses[ref] = status_for_project(ref, project) + end + + def status_for_project(ref, pipeline_project) + pipeline_project.pipelines.latest_status_per_commit(id, ref)[id] end def set_status_for_ref(ref, status) diff --git a/app/serializers/commit_entity.rb b/app/serializers/commit_entity.rb index 90406701bbb..a94e32478ce 100644 --- a/app/serializers/commit_entity.rb +++ b/app/serializers/commit_entity.rb @@ -30,6 +30,17 @@ class CommitEntity < API::Entities::Commit render('projects/commit/_signature', signature: commit.signature) if commit.has_signature? end + expose :pipeline_status_path, if: { type: :full } do |commit, options| + pipeline_ref = options[:pipeline_ref] + pipeline_project = options[:pipeline_project] || commit.project + next unless pipeline_ref && pipeline_project + + status = commit.status_for_project(pipeline_ref, pipeline_project) + next unless status + + pipelines_project_commit_path(pipeline_project, commit.id, ref: pipeline_ref) + end + def render(*args) return unless request.respond_to?(:render) && request.render.respond_to?(:call) diff --git a/app/serializers/diffs_entity.rb b/app/serializers/diffs_entity.rb index 00dc55fc004..b51e4a7e6d0 100644 --- a/app/serializers/diffs_entity.rb +++ b/app/serializers/diffs_entity.rb @@ -18,7 +18,9 @@ class DiffsEntity < Grape::Entity expose :commit do |diffs, options| CommitEntity.represent options[:commit], options.merge( type: :full, - commit_url_params: { merge_request_iid: merge_request&.iid } + commit_url_params: { merge_request_iid: merge_request&.iid }, + pipeline_ref: merge_request&.source_branch, + pipeline_project: merge_request&.source_project ) end diff --git a/spec/javascripts/diffs/components/commit_item_spec.js b/spec/javascripts/diffs/components/commit_item_spec.js index 50651d67172..8c3376c0eb3 100644 --- a/spec/javascripts/diffs/components/commit_item_spec.js +++ b/spec/javascripts/diffs/components/commit_item_spec.js @@ -10,6 +10,7 @@ const TEST_AUTHOR_NAME = 'test'; const TEST_AUTHOR_EMAIL = 'test+test@gitlab.com'; const TEST_AUTHOR_GRAVATAR = `${TEST_HOST}/avatar/test?s=36`; const TEST_SIGNATURE_HTML = '<a>Legit commit</a>'; +const TEST_PIPELINE_STATUS_PATH = `${TEST_HOST}/pipeline/status`; const getTitleElement = vm => vm.$el.querySelector('.commit-row-message.item-title'); const getDescElement = vm => vm.$el.querySelector('pre.commit-row-description'); @@ -143,4 +144,20 @@ describe('diffs/components/commit_widget', () => { expect(actionsElement).toContainHtml(TEST_SIGNATURE_HTML); }); }); + + describe('with pipeline status', () => { + beforeEach(done => { + vm.commit.pipelineStatusPath = TEST_PIPELINE_STATUS_PATH; + + vm.$nextTick() + .then(done) + .catch(done.fail); + }); + + it('renders pipeline status', () => { + const actionsElement = getCommitActionsElement(vm); + + expect(actionsElement).toContainElement('.ci-status-link'); + }); + }); }); diff --git a/spec/serializers/commit_entity_spec.rb b/spec/serializers/commit_entity_spec.rb index b8cd24c69a6..b9995818e98 100644 --- a/spec/serializers/commit_entity_spec.rb +++ b/spec/serializers/commit_entity_spec.rb @@ -66,7 +66,7 @@ describe CommitEntity do context 'when type is "full"' do let(:entity) do - described_class.new(commit, request: request, type: :full) + described_class.new(commit, request: request, type: :full, pipeline_ref: project.default_branch, pipeline_project: project) end it 'exposes extra properties' do @@ -84,6 +84,16 @@ describe CommitEntity do expect(subject.fetch(:signature_html)).to be SIGNATURE_HTML end end + + context 'when commit has pipeline' do + before do + create(:ci_pipeline, project: project, sha: commit.id) + end + + it 'exposes "pipeline_status_path"' do + expect(subject.fetch(:pipeline_status_path)).not_to be_nil + end + end end context 'when commit_url_params is set' do |