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
b9d0d013
Commit
b9d0d013
authored
Jun 10, 2020
by
Amparo Luna
Committed by
Dmytro Zaporozhets
Jun 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add blobs to SnippetType
parent
a7fe3895
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
126 additions
and
21 deletions
+126
-21
app/graphql/types/snippet_type.rb
app/graphql/types/snippet_type.rb
+5
-0
app/presenters/snippet_presenter.rb
app/presenters/snippet_presenter.rb
+6
-2
changelogs/unreleased/al-217784-add-blobs-field-to-snippets-in-graphql.yml
...ased/al-217784-add-blobs-field-to-snippets-in-graphql.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+5
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+26
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-0
spec/graphql/types/snippet_type_spec.rb
spec/graphql/types/snippet_type_spec.rb
+57
-19
spec/presenters/snippet_presenter_spec.rb
spec/presenters/snippet_presenter_spec.rb
+21
-0
No files found.
app/graphql/types/snippet_type.rb
View file @
b9d0d013
...
...
@@ -65,6 +65,11 @@ module Types
calls_gitaly:
true
,
null:
false
field
:blobs
,
type:
[
Types
::
Snippets
::
BlobType
],
description:
'Snippet blobs'
,
calls_gitaly:
true
,
null:
false
field
:ssh_url_to_repo
,
type:
GraphQL
::
STRING_TYPE
,
description:
'SSH URL to the snippet repository'
,
calls_gitaly:
true
,
...
...
app/presenters/snippet_presenter.rb
View file @
b9d0d013
...
...
@@ -36,10 +36,14 @@ class SnippetPresenter < Gitlab::View::Presenter::Delegated
end
def
blob
blobs
.
first
end
def
blobs
if
snippet
.
empty_repo?
snippet
.
blob
[
snippet
.
blob
]
else
snippet
.
blobs
.
first
snippet
.
blobs
end
end
...
...
changelogs/unreleased/al-217784-add-blobs-field-to-snippets-in-graphql.yml
0 → 100644
View file @
b9d0d013
---
title
:
Add blobs field to SnippetType in GraphQL
merge_request
:
33657
author
:
type
:
changed
doc/api/graphql/reference/gitlab_schema.graphql
View file @
b9d0d013
...
...
@@ -11003,6 +11003,11 @@ type Snippet implements Noteable {
"""
blob
:
SnippetBlob
!
"""
Snippet
blobs
"""
blobs
:
[
SnippetBlob
!]!
"""
Timestamp
this
snippet
was
created
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
b9d0d013
...
...
@@ -32475,6 +32475,32 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "blobs",
"description": "Snippet blobs",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "SnippetBlob",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdAt",
"description": "Timestamp this snippet was created",
doc/api/graphql/reference/index.md
View file @
b9d0d013
...
...
@@ -1603,6 +1603,7 @@ Represents a snippet entry
| --- | ---- | ---------- |
|
`author`
| User! | The owner of the snippet |
|
`blob`
| SnippetBlob! | Snippet blob |
|
`blobs`
| SnippetBlob! => Array | Snippet blobs |
|
`createdAt`
| Time! | Timestamp this snippet was created |
|
`description`
| String | Description of the snippet |
|
`descriptionHtml`
| String | The GitLab Flavored Markdown rendering of
`description`
|
...
...
spec/graphql/types/snippet_type_spec.rb
View file @
b9d0d013
...
...
@@ -11,7 +11,7 @@ describe GitlabSchema.types['Snippet'] do
:visibility_level
,
:created_at
,
:updated_at
,
:web_url
,
:raw_url
,
:ssh_url_to_repo
,
:http_url_to_repo
,
:notes
,
:discussions
,
:user_permissions
,
:description_html
,
:blob
]
:description_html
,
:blob
,
:blobs
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
end
...
...
@@ -76,30 +76,14 @@ describe GitlabSchema.types['Snippet'] do
describe
'#blob'
do
let
(
:query_blob
)
{
subject
.
dig
(
'data'
,
'snippets'
,
'edges'
)[
0
][
'node'
][
'blob'
]
}
let
(
:query
)
do
%(
{
snippets {
edges {
node {
blob {
name
path
}
}
}
}
}
)
end
subject
{
GitlabSchema
.
execute
(
query
,
context:
{
current_user:
user
}).
as_json
}
subject
{
GitlabSchema
.
execute
(
snippet_query_for
(
field:
'blob'
)
,
context:
{
current_user:
user
}).
as_json
}
context
'when snippet has repository'
do
let!
(
:snippet
)
{
create
(
:personal_snippet
,
:repository
,
:public
,
author:
user
)
}
let
(
:blob
)
{
snippet
.
blobs
.
first
}
it
'returns blob from the repository'
do
it
'returns
the first
blob from the repository'
do
expect
(
query_blob
[
'name'
]).
to
eq
blob
.
name
expect
(
query_blob
[
'path'
]).
to
eq
blob
.
path
end
...
...
@@ -115,4 +99,58 @@ describe GitlabSchema.types['Snippet'] do
end
end
end
describe
'#blobs'
do
let_it_be
(
:snippet
)
{
create
(
:personal_snippet
,
:public
,
author:
user
)
}
let
(
:query_blobs
)
{
subject
.
dig
(
'data'
,
'snippets'
,
'edges'
)[
0
][
'node'
][
'blobs'
]
}
subject
{
GitlabSchema
.
execute
(
snippet_query_for
(
field:
'blobs'
),
context:
{
current_user:
user
}).
as_json
}
shared_examples
'an array'
do
it
'returns an array of snippet blobs'
do
expect
(
query_blobs
).
to
be_an
(
Array
)
end
end
context
'when snippet does not have a repository'
do
let
(
:blob
)
{
snippet
.
blob
}
it_behaves_like
'an array'
it
'contains the first blob from the snippet'
do
expect
(
query_blobs
.
first
[
'name'
]).
to
eq
blob
.
name
expect
(
query_blobs
.
first
[
'path'
]).
to
eq
blob
.
path
end
end
context
'when snippet has repository'
do
let_it_be
(
:snippet
)
{
create
(
:personal_snippet
,
:repository
,
:public
,
author:
user
)
}
let
(
:blobs
)
{
snippet
.
blobs
}
it_behaves_like
'an array'
it
'contains all the blobs from the repository'
do
resulting_blobs_names
=
query_blobs
.
map
{
|
b
|
b
[
'name'
]
}
expect
(
resulting_blobs_names
).
to
match_array
(
blobs
.
map
(
&
:name
))
end
end
end
def
snippet_query_for
(
field
:)
%(
{
snippets {
edges {
node {
#{field} {
name
path
}
}
}
}
}
)
end
end
spec/presenters/snippet_presenter_spec.rb
View file @
b9d0d013
...
...
@@ -163,4 +163,25 @@ describe SnippetPresenter do
end
end
end
describe
'#blobs'
do
let
(
:snippet
)
{
personal_snippet
}
subject
{
presenter
.
blobs
}
context
'when snippet does not have a repository'
do
it
'returns an array with one SnippetBlob'
do
expect
(
subject
.
size
).
to
eq
(
1
)
expect
(
subject
.
first
).
to
eq
(
snippet
.
blob
)
end
end
context
'when snippet has a repository'
do
let
(
:snippet
)
{
create
(
:snippet
,
:repository
,
author:
user
)
}
it
'returns an array with all repository blobs'
do
expect
(
subject
).
to
match_array
(
snippet
.
blobs
)
end
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