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
d7cb66c0
Commit
d7cb66c0
authored
Jun 22, 2021
by
Gary Holtz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding raw_plain_data type to snippets
Changelog: added
parent
2fca139b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
7 deletions
+52
-7
app/graphql/types/snippets/blob_type.rb
app/graphql/types/snippets/blob_type.rb
+4
-0
app/presenters/blob_presenter.rb
app/presenters/blob_presenter.rb
+4
-0
app/presenters/snippet_blob_presenter.rb
app/presenters/snippet_blob_presenter.rb
+4
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-0
spec/graphql/types/snippets/blob_type_spec.rb
spec/graphql/types/snippets/blob_type_spec.rb
+2
-1
spec/presenters/blob_presenter_spec.rb
spec/presenters/blob_presenter_spec.rb
+16
-6
spec/presenters/snippet_blob_presenter_spec.rb
spec/presenters/snippet_blob_presenter_spec.rb
+21
-0
No files found.
app/graphql/types/snippets/blob_type.rb
View file @
d7cb66c0
...
...
@@ -16,6 +16,10 @@ module Types
description:
'Blob plain highlighted data.'
,
null:
true
field
:raw_plain_data
,
GraphQL
::
STRING_TYPE
,
description:
'The raw content of the blob, if the blob is text data.'
,
null:
true
field
:raw_path
,
GraphQL
::
STRING_TYPE
,
description:
'Blob raw content endpoint path.'
,
null:
false
...
...
app/presenters/blob_presenter.rb
View file @
d7cb66c0
...
...
@@ -26,6 +26,10 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
highlight
(
plain:
false
)
end
def
raw_plain_data
blob
.
data
unless
blob
.
binary?
end
def
web_url
url_helpers
.
project_blob_url
(
project
,
ref_qualified_path
)
end
...
...
app/presenters/snippet_blob_presenter.rb
View file @
d7cb66c0
...
...
@@ -17,6 +17,10 @@ class SnippetBlobPresenter < BlobPresenter
snippet_blob_raw_route
end
def
raw_plain_data
blob
.
data
unless
blob
.
binary?
end
private
def
snippet
...
...
doc/api/graphql/reference/index.md
View file @
d7cb66c0
...
...
@@ -12803,6 +12803,7 @@ Represents the snippet blob.
|
<a
id=
"snippetblobpath"
></a>
`path`
|
[
`String`
](
#string
)
| Blob path. |
|
<a
id=
"snippetblobplaindata"
></a>
`plainData`
|
[
`String`
](
#string
)
| Blob plain highlighted data. |
|
<a
id=
"snippetblobrawpath"
></a>
`rawPath`
|
[
`String!`
](
#string
)
| Blob raw content endpoint path. |
|
<a
id=
"snippetblobrawplaindata"
></a>
`rawPlainData`
|
[
`String`
](
#string
)
| The raw content of the blob, if the blob is text data. |
|
<a
id=
"snippetblobrenderedastext"
></a>
`renderedAsText`
|
[
`Boolean!`
](
#boolean
)
| Shows whether the blob is rendered as text. |
|
<a
id=
"snippetblobrichdata"
></a>
`richData`
|
[
`String`
](
#string
)
| Blob highlighted data. |
|
<a
id=
"snippetblobrichviewer"
></a>
`richViewer`
|
[
`SnippetBlobViewer`
](
#snippetblobviewer
)
| Blob content rich viewer. |
...
...
spec/graphql/types/snippets/blob_type_spec.rb
View file @
d7cb66c0
...
...
@@ -6,7 +6,7 @@ RSpec.describe GitlabSchema.types['SnippetBlob'] do
include
GraphqlHelpers
it
'has the correct fields'
do
expected_fields
=
[
:rich_data
,
:plain_data
,
expected_fields
=
[
:rich_data
,
:plain_data
,
:raw_plain_data
,
:raw_path
,
:size
,
:binary
,
:name
,
:path
,
:simple_viewer
,
:rich_viewer
,
:mode
,
:external_storage
,
:rendered_as_text
]
...
...
@@ -18,6 +18,7 @@ RSpec.describe GitlabSchema.types['SnippetBlob'] do
{
'richData'
=>
be_nullable
,
'plainData'
=>
be_nullable
,
'rawPlainData'
=>
be_nullable
,
'rawPath'
=>
be_non_null
,
'size'
=>
be_non_null
,
'binary'
=>
be_non_null
,
...
...
spec/presenters/blob_presenter_spec.rb
View file @
d7cb66c0
...
...
@@ -121,16 +121,26 @@ RSpec.describe BlobPresenter do
end
end
describe
'#plain_data'
do
describe
'#
raw_
plain_data'
do
let
(
:blob
)
{
repository
.
blob_at
(
'HEAD'
,
file
)
}
subject
{
described_class
.
new
(
blob
).
plain_data
}
context
'when blob is text'
do
let
(
:file
)
{
'files/ruby/popen.rb'
}
it
'does not include html in the content'
do
expect
(
presenter
.
raw_plain_data
.
include?
(
'</span>'
)).
to
be_falsey
end
end
end
describe
'#plain_data'
do
let
(
:blob
)
{
repository
.
blob_at
(
'HEAD'
,
file
)
}
context
'when blob is binary'
do
let
(
:file
)
{
'files/images/logo-black.png'
}
it
'returns nil'
do
expect
(
subject
).
to
be_nil
expect
(
presenter
.
plain_data
).
to
be_nil
end
end
...
...
@@ -138,7 +148,7 @@ RSpec.describe BlobPresenter do
let
(
:file
)
{
'README.md'
}
it
'returns plain content'
do
expect
(
subject
).
to
include
(
'<span id="LC1" class="line" lang="markdown">'
)
expect
(
presenter
.
plain_data
).
to
include
(
'<span id="LC1" class="line" lang="markdown">'
)
end
end
...
...
@@ -146,7 +156,7 @@ RSpec.describe BlobPresenter do
let
(
:file
)
{
'files/ruby/regex.rb'
}
it
'returns highlighted syntax content'
do
expect
(
subject
)
expect
(
presenter
.
plain_data
)
.
to
include
'<span id="LC1" class="line" lang="ruby"><span class="k">module</span> <span class="nn">Gitlab</span>'
end
end
...
...
@@ -155,7 +165,7 @@ RSpec.describe BlobPresenter do
let
(
:file
)
{
'LICENSE'
}
it
'returns plain text highlighted content'
do
expect
(
subject
).
to
include
(
'<span id="LC1" class="line" lang="plaintext">The MIT License (MIT)</span>'
)
expect
(
presenter
.
plain_data
).
to
include
(
'<span id="LC1" class="line" lang="plaintext">The MIT License (MIT)</span>'
)
end
end
end
...
...
spec/presenters/snippet_blob_presenter_spec.rb
View file @
d7cb66c0
...
...
@@ -120,6 +120,27 @@ RSpec.describe SnippetBlobPresenter do
end
end
describe
'#raw_plain_data'
do
context
"with a plain file"
do
subject
{
described_class
.
new
(
blob
,
current_user:
user
)
}
it
'shows raw data for non binary files'
do
expect
(
subject
.
raw_plain_data
).
to
eq
(
blob
.
data
)
end
end
context
"with a binary file"
do
let
(
:file
)
{
'files/images/logo-black.png'
}
let
(
:blob
)
{
blob_at
(
file
)
}
subject
{
described_class
.
new
(
blob
,
current_user:
user
)
}
it
'returns nil'
do
expect
(
subject
.
raw_plain_data
).
to
be_nil
end
end
end
describe
'#raw_url'
do
subject
{
described_class
.
new
(
blob
,
current_user:
user
).
raw_url
}
...
...
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