Commit 5a286eb7 authored by Paul Slaughter's avatar Paul Slaughter

Add signature badge to diffs/commit_item

**Notes:**
- Also exposes commit.signature_html in diffs.json
parent c375171b
...@@ -102,6 +102,10 @@ export default { ...@@ -102,6 +102,10 @@ export default {
></pre> ></pre>
</div> </div>
<div class="commit-actions flex-row d-none d-sm-flex"> <div class="commit-actions flex-row d-none d-sm-flex">
<div
v-if="commit.signatureHtml"
v-html="commit.signatureHtml"
></div>
<div class="commit-sha-group"> <div class="commit-sha-group">
<div <div
class="label label-monospace" class="label label-monospace"
......
...@@ -25,7 +25,13 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic ...@@ -25,7 +25,13 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
@diffs.write_cache @diffs.write_cache
render json: DiffsSerializer.new(current_user: current_user, project: @merge_request.project).represent(@diffs, additional_attributes) request = {
current_user: current_user,
project: @merge_request.project,
render: ->(partial, locals) { view_to_html_string(partial, locals) }
}
render json: DiffsSerializer.new(request).represent(@diffs, additional_attributes)
end end
def define_diff_vars def define_diff_vars
......
...@@ -25,4 +25,14 @@ class CommitEntity < API::Entities::Commit ...@@ -25,4 +25,14 @@ class CommitEntity < API::Entities::Commit
expose :title_html, if: { type: :full } do |commit| expose :title_html, if: { type: :full } do |commit|
markdown_field(commit, :title) markdown_field(commit, :title)
end end
expose :signature_html, if: { type: :full } do |commit|
render('projects/commit/_signature', signature: commit.signature) if commit.has_signature?
end
def render(*args)
return unless request.respond_to?(:render) && request.render.respond_to?(:call)
request.render.call(*args)
end
end end
...@@ -9,6 +9,7 @@ import getDiffWithCommit from '../mock_data/diff_with_commit'; ...@@ -9,6 +9,7 @@ import getDiffWithCommit from '../mock_data/diff_with_commit';
const TEST_AUTHOR_NAME = 'test'; const TEST_AUTHOR_NAME = 'test';
const TEST_AUTHOR_EMAIL = 'test+test@gitlab.com'; const TEST_AUTHOR_EMAIL = 'test+test@gitlab.com';
const TEST_AUTHOR_GRAVATAR = `${TEST_HOST}/avatar/test?s=36`; const TEST_AUTHOR_GRAVATAR = `${TEST_HOST}/avatar/test?s=36`;
const TEST_SIGNATURE_HTML = '<a>Legit commit</a>';
const getTitleElement = vm => vm.$el.querySelector('.commit-row-message.item-title'); const getTitleElement = vm => vm.$el.querySelector('.commit-row-message.item-title');
const getDescElement = vm => vm.$el.querySelector('pre.commit-row-description'); const getDescElement = vm => vm.$el.querySelector('pre.commit-row-description');
...@@ -16,6 +17,7 @@ const getDescExpandElement = vm => vm.$el.querySelector('.commit-content .text-e ...@@ -16,6 +17,7 @@ const getDescExpandElement = vm => vm.$el.querySelector('.commit-content .text-e
const getShaElement = vm => vm.$el.querySelector('.commit-sha-group'); const getShaElement = vm => vm.$el.querySelector('.commit-sha-group');
const getAvatarElement = vm => vm.$el.querySelector('.user-avatar-link'); const getAvatarElement = vm => vm.$el.querySelector('.user-avatar-link');
const getCommitterElement = vm => vm.$el.querySelector('.commiter'); const getCommitterElement = vm => vm.$el.querySelector('.commiter');
const getCommitActionsElement = vm => vm.$el.querySelector('.commit-actions');
describe('diffs/components/commit_widget', () => { describe('diffs/components/commit_widget', () => {
const Component = Vue.extend(CommitItem); const Component = Vue.extend(CommitItem);
...@@ -125,4 +127,20 @@ describe('diffs/components/commit_widget', () => { ...@@ -125,4 +127,20 @@ describe('diffs/components/commit_widget', () => {
expect(nameElement).toHaveText(TEST_AUTHOR_NAME); expect(nameElement).toHaveText(TEST_AUTHOR_NAME);
}); });
}); });
describe('with signature', () => {
beforeEach(done => {
vm.commit.signatureHtml = TEST_SIGNATURE_HTML;
vm.$nextTick()
.then(done)
.catch(done.fail);
});
it('renders signature html', () => {
const actionsElement = getCommitActionsElement(vm);
expect(actionsElement).toContainHtml(TEST_SIGNATURE_HTML);
});
});
}); });
require 'spec_helper' require 'spec_helper'
describe CommitEntity do describe CommitEntity do
SIGNATURE_HTML = 'TEST'.freeze
let(:entity) do let(:entity) do
described_class.new(commit, request: request) described_class.new(commit, request: request)
end end
let(:request) { double('request') } let(:request) { double('request') }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:commit) { project.commit } let(:commit) { project.commit }
...@@ -12,7 +13,11 @@ describe CommitEntity do ...@@ -12,7 +13,11 @@ describe CommitEntity do
subject { entity.as_json } subject { entity.as_json }
before do before do
render = double('render')
allow(render).to receive(:call).and_return(SIGNATURE_HTML)
allow(request).to receive(:project).and_return(project) allow(request).to receive(:project).and_return(project)
allow(request).to receive(:render).and_return(render)
end end
context 'when commit author is a user' do context 'when commit author is a user' do
...@@ -70,6 +75,15 @@ describe CommitEntity do ...@@ -70,6 +75,15 @@ describe CommitEntity do
expect(subject.fetch(:description_html)).not_to be_nil expect(subject.fetch(:description_html)).not_to be_nil
expect(subject.fetch(:title_html)).not_to be_nil expect(subject.fetch(:title_html)).not_to be_nil
end end
context 'when commit has signature' do
let(:commit) { project.commit(TestEnv::BRANCH_SHA['signed-commits']) }
it 'exposes "signature_html"' do
expect(request.render).to receive(:call)
expect(subject.fetch(:signature_html)).to be SIGNATURE_HTML
end
end
end end
context 'when commit_url_params is set' do context 'when commit_url_params is set' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment