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
e579b3f0
Commit
e579b3f0
authored
Jul 15, 2020
by
Greg Messner
Browse files
Fixed createSnippet() for GitLab 13.0 (#580)
parent
d49bc739
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
e579b3f0
...
@@ -2307,27 +2307,32 @@ public class ProjectApi extends AbstractApi implements Constants {
...
@@ -2307,27 +2307,32 @@ public class ProjectApi extends AbstractApi implements Constants {
public
Snippet
createSnippet
(
Object
projectIdOrPath
,
String
title
,
String
filename
,
String
description
,
public
Snippet
createSnippet
(
Object
projectIdOrPath
,
String
title
,
String
filename
,
String
description
,
String
content
,
Visibility
visibility
)
throws
GitLabApiException
{
String
content
,
Visibility
visibility
)
throws
GitLabApiException
{
// 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"
,
content
,
true
)
.
withParam
(
"visibility"
,
visibility
,
true
);
try
{
try
{
// GitLab 12.9 and newer
Snippet
snippet
=
new
Snippet
(
title
,
filename
,
content
,
visibility
,
description
);
GitLabApiForm
form
=
new
GitLabApiForm
()
Response
response
=
post
(
Response
.
Status
.
CREATED
,
snippet
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"snippets"
);
.
withParam
(
"title"
,
title
,
true
)
.
withParam
(
"file_name"
,
filename
,
true
)
.
withParam
(
"description"
,
description
)
.
withParam
(
"content"
,
content
,
true
)
.
withParam
(
"visibility"
,
visibility
,
true
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
form
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"snippets"
);
return
(
response
.
readEntity
(
Snippet
.
class
));
return
(
response
.
readEntity
(
Snippet
.
class
));
}
catch
(
GitLabApiException
e
)
{
}
catch
(
GitLabApiException
gla
e
)
{
// GitLab 12.8 and older will return HTTP status 400 if called with content instead of code
// 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
())
{
if
(
gla
e
.
getHttpStatus
()
!=
Response
.
Status
.
BAD_REQUEST
.
getStatusCode
())
{
throw
e
;
throw
gla
e
;
}
}
GitLabApiForm
form
=
new
GitLabApiForm
()
.
withParam
(
"title"
,
title
,
true
)
.
withParam
(
"file_name"
,
filename
,
true
)
.
withParam
(
"description"
,
description
)
.
withParam
(
"code"
,
content
,
true
)
.
withParam
(
"visibility"
,
visibility
,
true
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
form
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"snippets"
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
form
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"snippets"
);
return
(
response
.
readEntity
(
Snippet
.
class
));
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