Commit 048c1130 authored by Igor Drozdov's avatar Igor Drozdov

Add signatureHtml field for last-commit GQL

It allows FE to display signature for the last commit
parent 5e21cc09
......@@ -125,6 +125,7 @@ export default {
</pre>
</div>
<div class="commit-actions flex-row">
<div v-if="commit.signatureHtml" v-html="commit.signatureHtml"></div>
<gl-link
v-if="commit.latestPipeline"
v-gl-tooltip
......
......@@ -13,6 +13,7 @@ query pathLastCommit($projectPath: ID!, $path: String, $ref: String!) {
avatarUrl
webUrl
}
signatureHtml
latestPipeline {
detailedStatus {
detailsPath
......
# frozen_string_literal: true
module Resolvers
class LastCommitResolver < BaseResolver
type Types::CommitType, null: true
alias_method :tree, :object
def resolve(**args)
# Ensure merge commits can be returned by sending nil to Gitaly instead of '/'
path = tree.path == '/' ? nil : tree.path
commit = Gitlab::Git::Commit.last_for_path(tree.repository, tree.sha, path)
::Commit.new(commit, tree.repository.project) if commit
end
end
end
......@@ -15,6 +15,8 @@ module Types
field :message, type: GraphQL::STRING_TYPE, null: true # rubocop:disable Graphql/Descriptions
field :authored_date, type: Types::TimeType, null: true # rubocop:disable Graphql/Descriptions
field :web_url, type: GraphQL::STRING_TYPE, null: false # rubocop:disable Graphql/Descriptions
field :signature_html, type: GraphQL::STRING_TYPE,
null: true, calls_gitaly: true, description: 'Rendered html for the commit signature'
# models/commit lazy loads the author by email
field :author, type: Types::UserType, null: true # rubocop:disable Graphql/Descriptions
......
......@@ -7,9 +7,9 @@ module Types
graphql_name 'Tree'
# Complexity 10 as it triggers a Gitaly call on each render
field :last_commit, Types::CommitType, null: true, complexity: 10, calls_gitaly: true, resolve: -> (tree, args, ctx) do # rubocop:disable Graphql/Descriptions
tree.repository.last_commit_for_path(tree.sha, tree.path)
end
field :last_commit, Types::CommitType,
null: true, complexity: 10, calls_gitaly: true, resolver: Resolvers::LastCommitResolver,
description: 'Last commit for the tree'
field :trees, Types::Tree::TreeEntryType.connection_type, null: false, resolve: -> (obj, args, ctx) do # rubocop:disable Graphql/Descriptions
Gitlab::Graphql::Representation::TreeEntry.decorate(obj.trees, obj.repository)
......
......@@ -20,4 +20,15 @@ class CommitPresenter < Gitlab::View::Presenter::Delegated
def web_url
Gitlab::UrlBuilder.new(commit).url
end
def signature_html
return unless commit.has_signature?
ApplicationController.renderer.render(
'projects/commit/_signature',
locals: { signature: commit.signature },
layout: false,
formats: [:html]
)
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Resolvers::LastCommitResolver do
include GraphqlHelpers
let(:repository) { create(:project, :repository).repository }
let(:tree) { repository.tree(ref, path) }
let(:commit) { resolve(described_class, obj: tree) }
describe '#resolve' do
context 'last commit is a merge commit' do
let(:ref) { 'master' }
let(:path) { '/' }
it 'resolves to the merge commit' do
expect(commit).to eq(repository.commits(ref, limit: 1).last)
end
end
context 'last commit for a different branch and path' do
let(:ref) { 'fix' }
let(:path) { 'files' }
it 'resolves commit' do
expect(commit).to eq(repository.commits(ref, path: path, limit: 1).last)
end
end
context 'last commit does not exist' do
let(:ref) { 'master' }
let(:path) { 'does-not-exist' }
it 'returns nil' do
expect(commit).to be_nil
end
end
end
end
......@@ -7,5 +7,10 @@ describe GitlabSchema.types['Commit'] do
it { expect(described_class).to require_graphql_authorizations(:download_code) }
it { expect(described_class).to have_graphql_fields(:id, :sha, :title, :description, :message, :authored_date, :author, :web_url, :latest_pipeline) }
it 'contains attributes related to commit' do
expect(described_class).to have_graphql_fields(
:id, :sha, :title, :description, :message, :authored_date,
:author, :web_url, :latest_pipeline, :signature_html
)
end
end
......@@ -55,4 +55,17 @@ describe CommitPresenter do
end
end
end
describe '#signature_html' do
let(:signature) { 'signature' }
before do
expect(commit).to receive(:has_signature?).and_return(true)
allow(ApplicationController.renderer).to receive(:render).and_return(signature)
end
it 'renders html for displaying signature' do
expect(presenter.signature_html).to eq(signature)
end
end
end
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