Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
3b98987d
Commit
3b98987d
authored
Jul 14, 2020
by
Greg Messner
Browse files
Fixed createSnippet() for GitLab 13.0 (#580)
parent
a082fb47
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
3b98987d
...
...
@@ -2299,23 +2299,38 @@ public class ProjectApi extends AbstractApi implements Constants {
* @param title the title of a snippet, required
* @param filename the name of a snippet file, required
* @param description the description of a snippet, optional
* @param co
de
the content of a snippet, required
* @param co
ntent
the content of a snippet, required
* @param visibility the snippet's visibility, required
* @return a Snippet instance with info on the created snippet
* @throws GitLabApiException if any exception occurs
*/
public
Snippet
createSnippet
(
Object
projectIdOrPath
,
String
title
,
String
filename
,
String
description
,
String
co
de
,
Visibility
visibility
)
throws
GitLabApiException
{
String
co
ntent
,
Visibility
visibility
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
// Use a GitLabApiForm to validate the parameters.
GitLabApiForm
form
=
new
GitLabApiForm
()
.
withParam
(
"title"
,
title
,
true
)
.
withParam
(
"file_name"
,
filename
,
true
)
.
withParam
(
"description"
,
description
)
.
withParam
(
"code"
,
co
de
,
true
)
.
withParam
(
"code"
,
co
ntent
,
true
)
.
withParam
(
"visibility"
,
visibility
,
true
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"snippets"
);
return
(
response
.
readEntity
(
Snippet
.
class
));
try
{
// GitLab 12.9 and newer
Snippet
snippet
=
new
Snippet
(
title
,
filename
,
content
,
visibility
,
description
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
snippet
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"snippets"
);
return
(
response
.
readEntity
(
Snippet
.
class
));
}
catch
(
GitLabApiException
e
)
{
// GitLab 12.8 and older will return HTTP status 400 if called with content instead of code
if
(
e
.
getHttpStatus
()
!=
Response
.
Status
.
BAD_REQUEST
.
getStatusCode
())
{
throw
e
;
}
Response
response
=
post
(
Response
.
Status
.
CREATED
,
form
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"snippets"
);
return
(
response
.
readEntity
(
Snippet
.
class
));
}
}
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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