Commit e579b3f0 authored by Greg Messner's avatar Greg Messner
Browse files

Fixed createSnippet() for GitLab 13.0 (#580)

parent d49bc739
...@@ -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 glae) {
// 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 (glae.getHttpStatus() != Response.Status.BAD_REQUEST.getStatusCode()) {
throw e; throw glae;
} }
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));
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment