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
0b92a595
Commit
0b92a595
authored
Apr 29, 2020
by
Vijay Hawoldar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove instances of deprecated Snippet code calls
parent
69304a32
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
49 deletions
+15
-49
changelogs/unreleased/vij-snippet-code-references.yml
changelogs/unreleased/vij-snippet-code-references.yml
+5
-0
lib/api/project_snippets.rb
lib/api/project_snippets.rb
+1
-8
spec/requests/api/project_snippets_spec.rb
spec/requests/api/project_snippets_spec.rb
+9
-41
No files found.
changelogs/unreleased/vij-snippet-code-references.yml
0 → 100644
View file @
0b92a595
---
title
:
Remove deprecated Snippet `code` attribute from Project Snippets API
merge_request
:
30739
author
:
type
:
other
lib/api/project_snippets.rb
View file @
0b92a595
...
...
@@ -57,18 +57,15 @@ module API
params
do
requires
:title
,
type:
String
,
desc:
'The title of the snippet'
requires
:file_name
,
type:
String
,
desc:
'The file name of the snippet'
optional
:code
,
type:
String
,
allow_blank:
false
,
desc:
'The content of the snippet (deprecated in favor of "content")'
optional
:content
,
type:
String
,
allow_blank:
false
,
desc:
'The content of the snippet'
optional
:description
,
type:
String
,
desc:
'The description of a snippet'
requires
:visibility
,
type:
String
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
desc:
'The visibility of the snippet'
mutually_exclusive
:code
,
:content
end
post
":id/snippets"
do
authorize!
:create_snippet
,
user_project
snippet_params
=
declared_params
(
include_missing:
false
).
merge
(
request:
request
,
api:
true
)
snippet_params
[
:content
]
=
snippet_params
.
delete
(
:code
)
if
snippet_params
[
:code
].
present?
service_response
=
::
Snippets
::
CreateService
.
new
(
user_project
,
current_user
,
snippet_params
).
execute
snippet
=
service_response
.
payload
[
:snippet
]
...
...
@@ -89,14 +86,12 @@ module API
requires
:snippet_id
,
type:
Integer
,
desc:
'The ID of a project snippet'
optional
:title
,
type:
String
,
desc:
'The title of the snippet'
optional
:file_name
,
type:
String
,
desc:
'The file name of the snippet'
optional
:code
,
type:
String
,
allow_blank:
false
,
desc:
'The content of the snippet (deprecated in favor of "content")'
optional
:content
,
type:
String
,
allow_blank:
false
,
desc:
'The content of the snippet'
optional
:description
,
type:
String
,
desc:
'The description of a snippet'
optional
:visibility
,
type:
String
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
desc:
'The visibility of the snippet'
at_least_one_of
:title
,
:file_name
,
:code
,
:content
,
:visibility_level
mutually_exclusive
:code
,
:content
at_least_one_of
:title
,
:file_name
,
:content
,
:visibility_level
end
# rubocop: disable CodeReuse/ActiveRecord
put
":id/snippets/:snippet_id"
do
...
...
@@ -108,8 +103,6 @@ module API
snippet_params
=
declared_params
(
include_missing:
false
)
.
merge
(
request:
request
,
api:
true
)
snippet_params
[
:content
]
=
snippet_params
.
delete
(
:code
)
if
snippet_params
[
:code
].
present?
service_response
=
::
Snippets
::
UpdateService
.
new
(
user_project
,
current_user
,
snippet_params
).
execute
(
snippet
)
snippet
=
service_response
.
payload
[
:snippet
]
...
...
spec/requests/api/project_snippets_spec.rb
View file @
0b92a595
...
...
@@ -119,7 +119,7 @@ describe API::ProjectSnippets do
title:
'Test Title'
,
file_name:
'test.rb'
,
description:
'test description'
,
co
de
:
'puts "hello world"'
,
co
ntent
:
'puts "hello world"'
,
visibility:
'public'
}
end
...
...
@@ -138,7 +138,7 @@ describe API::ProjectSnippets do
blob
=
snippet
.
repository
.
blob_at
(
'master'
,
params
[
:file_name
])
expect
(
blob
.
data
).
to
eq
params
[
:co
de
]
expect
(
blob
.
data
).
to
eq
params
[
:co
ntent
]
end
end
...
...
@@ -180,7 +180,7 @@ describe API::ProjectSnippets do
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
snippet
=
ProjectSnippet
.
find
(
json_response
[
'id'
])
expect
(
snippet
.
content
).
to
eq
(
params
[
:co
de
])
expect
(
snippet
.
content
).
to
eq
(
params
[
:co
ntent
])
expect
(
snippet
.
description
).
to
eq
(
params
[
:description
])
expect
(
snippet
.
title
).
to
eq
(
params
[
:title
])
expect
(
snippet
.
file_name
).
to
eq
(
params
[
:file_name
])
...
...
@@ -197,7 +197,7 @@ describe API::ProjectSnippets do
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
snippet
=
ProjectSnippet
.
find
(
json_response
[
'id'
])
expect
(
snippet
.
content
).
to
eq
(
params
[
:co
de
])
expect
(
snippet
.
content
).
to
eq
(
params
[
:co
ntent
])
expect
(
snippet
.
description
).
to
eq
(
params
[
:description
])
expect
(
snippet
.
title
).
to
eq
(
params
[
:title
])
expect
(
snippet
.
file_name
).
to
eq
(
params
[
:file_name
])
...
...
@@ -208,29 +208,6 @@ describe API::ProjectSnippets do
subject
{
post
api
(
"/projects/
#{
project
.
id
}
/snippets/"
,
admin
),
params:
params
}
end
it
'creates a new snippet with content parameter'
do
params
[
:content
]
=
params
.
delete
(
:code
)
post
api
(
"/projects/
#{
project
.
id
}
/snippets/"
,
admin
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
snippet
=
ProjectSnippet
.
find
(
json_response
[
'id'
])
expect
(
snippet
.
content
).
to
eq
(
params
[
:content
])
expect
(
snippet
.
description
).
to
eq
(
params
[
:description
])
expect
(
snippet
.
title
).
to
eq
(
params
[
:title
])
expect
(
snippet
.
file_name
).
to
eq
(
params
[
:file_name
])
expect
(
snippet
.
visibility_level
).
to
eq
(
Snippet
::
PUBLIC
)
end
it
'returns 400 when both code and content parameters specified'
do
params
[
:content
]
=
params
[
:code
]
post
api
(
"/projects/
#{
project
.
id
}
/snippets/"
,
admin
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'error'
]).
to
eq
(
'code, content are mutually exclusive'
)
end
it
'returns 400 for missing parameters'
do
params
.
delete
(
:title
)
...
...
@@ -239,8 +216,8 @@ describe API::ProjectSnippets do
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it
'returns 400 for empty co
de
field'
do
params
[
:co
de
]
=
''
it
'returns 400 for empty co
ntent
field'
do
params
[
:co
ntent
]
=
''
post
api
(
"/projects/
#{
project
.
id
}
/snippets/"
,
admin
),
params:
params
...
...
@@ -298,7 +275,7 @@ describe API::ProjectSnippets do
new_content
=
'New content'
new_description
=
'New description'
update_snippet
(
params:
{
co
de
:
new_content
,
description:
new_description
,
visibility:
'private'
})
update_snippet
(
params:
{
co
ntent
:
new_content
,
description:
new_description
,
visibility:
'private'
})
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
snippet
.
reload
...
...
@@ -319,13 +296,6 @@ describe API::ProjectSnippets do
expect
(
snippet
.
description
).
to
eq
(
new_description
)
end
it
'returns 400 when both code and content parameters specified'
do
update_snippet
(
params:
{
code:
'some content'
,
content:
'other content'
})
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'error'
]).
to
eq
(
'code, content are mutually exclusive'
)
end
it
'returns 404 for invalid snippet id'
do
update_snippet
(
snippet_id:
non_existing_record_id
,
params:
{
title:
'foo'
})
...
...
@@ -339,10 +309,8 @@ describe API::ProjectSnippets do
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it
'returns 400 for empty code field'
do
new_content
=
''
update_snippet
(
params:
{
code:
new_content
})
it
'returns 400 for empty content field'
do
update_snippet
(
params:
{
content:
''
})
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
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