Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
048c1130
Commit
048c1130
authored
Sep 19, 2019
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add signatureHtml field for last-commit GQL
It allows FE to display signature for the last commit
parent
5e21cc09
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
95 additions
and
4 deletions
+95
-4
app/assets/javascripts/repository/components/last_commit.vue
app/assets/javascripts/repository/components/last_commit.vue
+1
-0
app/assets/javascripts/repository/queries/pathLastCommit.query.graphql
...vascripts/repository/queries/pathLastCommit.query.graphql
+1
-0
app/graphql/resolvers/last_commit_resolver.rb
app/graphql/resolvers/last_commit_resolver.rb
+17
-0
app/graphql/types/commit_type.rb
app/graphql/types/commit_type.rb
+2
-0
app/graphql/types/tree/tree_type.rb
app/graphql/types/tree/tree_type.rb
+3
-3
app/presenters/commit_presenter.rb
app/presenters/commit_presenter.rb
+11
-0
spec/graphql/resolvers/last_commit_resolver_spec.rb
spec/graphql/resolvers/last_commit_resolver_spec.rb
+41
-0
spec/graphql/types/commit_type_spec.rb
spec/graphql/types/commit_type_spec.rb
+6
-1
spec/presenters/commit_presenter_spec.rb
spec/presenters/commit_presenter_spec.rb
+13
-0
No files found.
app/assets/javascripts/repository/components/last_commit.vue
View file @
048c1130
...
...
@@ -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
...
...
app/assets/javascripts/repository/queries/pathLastCommit.query.graphql
View file @
048c1130
...
...
@@ -13,6 +13,7 @@ query pathLastCommit($projectPath: ID!, $path: String, $ref: String!) {
avatarUrl
webUrl
}
signatureHtml
latestPipeline
{
detailedStatus
{
detailsPath
...
...
app/graphql/resolvers/last_commit_resolver.rb
0 → 100644
View file @
048c1130
# 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
app/graphql/types/commit_type.rb
View file @
048c1130
...
...
@@ -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
...
...
app/graphql/types/tree/tree_type.rb
View file @
048c1130
...
...
@@ -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
)
...
...
app/presenters/commit_presenter.rb
View file @
048c1130
...
...
@@ -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
spec/graphql/resolvers/last_commit_resolver_spec.rb
0 → 100644
View file @
048c1130
# 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
spec/graphql/types/commit_type_spec.rb
View file @
048c1130
...
...
@@ -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
spec/presenters/commit_presenter_spec.rb
View file @
048c1130
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment