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
de41d5c3
Commit
de41d5c3
authored
Aug 29, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
0c6a5916
9bd6f336
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
5 deletions
+56
-5
changelogs/unreleased/sh-support-content-for-snippets-api.yml
...gelogs/unreleased/sh-support-content-for-snippets-api.yml
+5
-0
lib/api/project_snippets.rb
lib/api/project_snippets.rb
+9
-5
spec/requests/api/project_snippets_spec.rb
spec/requests/api/project_snippets_spec.rb
+42
-0
No files found.
changelogs/unreleased/sh-support-content-for-snippets-api.yml
0 → 100644
View file @
de41d5c3
---
title
:
Standardize use of `content` parameter in snippets API
merge_request
:
32296
author
:
type
:
changed
lib/api/project_snippets.rb
View file @
de41d5c3
...
@@ -51,16 +51,18 @@ module API
...
@@ -51,16 +51,18 @@ module API
params
do
params
do
requires
:title
,
type:
String
,
desc:
'The title of the snippet'
requires
:title
,
type:
String
,
desc:
'The title of the snippet'
requires
:file_name
,
type:
String
,
desc:
'The file name of the snippet'
requires
:file_name
,
type:
String
,
desc:
'The file name of the snippet'
requires
:code
,
type:
String
,
allow_blank:
false
,
desc:
'The content 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
:description
,
type:
String
,
desc:
'The description of a snippet'
requires
:visibility
,
type:
String
,
requires
:visibility
,
type:
String
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
desc:
'The visibility of the snippet'
desc:
'The visibility of the snippet'
mutually_exclusive
:code
,
:content
end
end
post
":id/snippets"
do
post
":id/snippets"
do
authorize!
:create_project_snippet
,
user_project
authorize!
:create_project_snippet
,
user_project
snippet_params
=
declared_params
.
merge
(
request:
request
,
api:
true
)
snippet_params
=
declared_params
(
include_missing:
false
)
.
merge
(
request:
request
,
api:
true
)
snippet_params
[
:content
]
=
snippet_params
.
delete
(
:code
)
snippet_params
[
:content
]
=
snippet_params
.
delete
(
:code
)
if
snippet_params
[
:code
].
present?
snippet
=
CreateSnippetService
.
new
(
user_project
,
current_user
,
snippet_params
).
execute
snippet
=
CreateSnippetService
.
new
(
user_project
,
current_user
,
snippet_params
).
execute
...
@@ -80,12 +82,14 @@ module API
...
@@ -80,12 +82,14 @@ module API
requires
:snippet_id
,
type:
Integer
,
desc:
'The ID of a project snippet'
requires
:snippet_id
,
type:
Integer
,
desc:
'The ID of a project snippet'
optional
:title
,
type:
String
,
desc:
'The title of the snippet'
optional
:title
,
type:
String
,
desc:
'The title of the snippet'
optional
:file_name
,
type:
String
,
desc:
'The file name 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'
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
:description
,
type:
String
,
desc:
'The description of a snippet'
optional
:visibility
,
type:
String
,
optional
:visibility
,
type:
String
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
desc:
'The visibility of the snippet'
desc:
'The visibility of the snippet'
at_least_one_of
:title
,
:file_name
,
:code
,
:visibility_level
at_least_one_of
:title
,
:file_name
,
:code
,
:content
,
:visibility_level
mutually_exclusive
:code
,
:content
end
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
put
":id/snippets/:snippet_id"
do
put
":id/snippets/:snippet_id"
do
...
...
spec/requests/api/project_snippets_spec.rb
View file @
de41d5c3
...
@@ -108,6 +108,29 @@ describe API::ProjectSnippets do
...
@@ -108,6 +108,29 @@ describe API::ProjectSnippets do
expect
(
snippet
.
visibility_level
).
to
eq
(
Snippet
::
PUBLIC
)
expect
(
snippet
.
visibility_level
).
to
eq
(
Snippet
::
PUBLIC
)
end
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
(
201
)
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
(
400
)
expect
(
json_response
[
'error'
]).
to
eq
(
'code, content are mutually exclusive'
)
end
it
'returns 400 for missing parameters'
do
it
'returns 400 for missing parameters'
do
params
.
delete
(
:title
)
params
.
delete
(
:title
)
...
@@ -175,6 +198,25 @@ describe API::ProjectSnippets do
...
@@ -175,6 +198,25 @@ describe API::ProjectSnippets do
expect
(
snippet
.
description
).
to
eq
(
new_description
)
expect
(
snippet
.
description
).
to
eq
(
new_description
)
end
end
it
'updates snippet with content parameter'
do
new_content
=
'New content'
new_description
=
'New description'
put
api
(
"/projects/
#{
snippet
.
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
,
admin
),
params:
{
content:
new_content
,
description:
new_description
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
snippet
.
reload
expect
(
snippet
.
content
).
to
eq
(
new_content
)
expect
(
snippet
.
description
).
to
eq
(
new_description
)
end
it
'returns 400 when both code and content parameters specified'
do
put
api
(
"/projects/
#{
snippet
.
project
.
id
}
/snippets/1234"
,
admin
),
params:
{
code:
'some content'
,
content:
'other content'
}
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'error'
]).
to
eq
(
'code, content are mutually exclusive'
)
end
it
'returns 404 for invalid snippet id'
do
it
'returns 404 for invalid snippet id'
do
put
api
(
"/projects/
#{
snippet
.
project
.
id
}
/snippets/1234"
,
admin
),
params:
{
title:
'foo'
}
put
api
(
"/projects/
#{
snippet
.
project
.
id
}
/snippets/1234"
,
admin
),
params:
{
title:
'foo'
}
...
...
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