From f6b9a5b1746d4fe1de6b05c36a0c005b845be6d4 Mon Sep 17 00:00:00 2001 From: renjie <1354334940@qq.com> Date: Wed, 20 Jun 2018 11:01:11 +0800 Subject: [PATCH 1/8] add getProject(int projectId, boolean statistics) api --- src/main/java/org/gitlab4j/api/ProjectApi.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java index 260f846b5..c0930a56f 100644 --- a/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -477,6 +477,22 @@ public Project getProject(Integer projectId) throws GitLabApiException { return (response.readEntity(Project.class)); } + /** + * Get a specific project, which is owned by the authentication user. + * + * GET /projects/:id + * + * @param projectId the ID of the project to get + * @param statistics include project statistics + * @return the specified project + * @throws GitLabApiException if any exception occurs + */ + public Project getProject(Integer projectId, Boolean statistics) throws GitLabApiException { + Form formData = new GitLabApiForm().withParam("statistics", statistics); + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId); + return (response.readEntity(Project.class)); + } + /** * Get an Optional instance with the value for the specific project, which is owned by the authentication user. * From db80879675e1f7068128c09b465ff1b1dcc91106 Mon Sep 17 00:00:00 2001 From: renjie <1354334940@qq.com> Date: Wed, 20 Jun 2018 11:06:53 +0800 Subject: [PATCH 2/8] add getProject(String namespace, String project, Boolean statistics) api --- .../java/org/gitlab4j/api/ProjectApi.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java index c0930a56f..1aa6686e7 100644 --- a/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -540,6 +540,39 @@ public Project getProject(String namespace, String project) throws GitLabApiExce return (response.readEntity(Project.class)); } + /** + * Get a specific project, which is owned by the authentication user. + * + * GET /projects/:id + * + * @param namespace the name of the project namespace or group + * @param project the name of the project to get + * @param statistics include project statistics + * @return the specified project + * @throws GitLabApiException if any exception occurs + */ + public Project getProject(String namespace, String project, Boolean statistics) throws GitLabApiException { + + if (namespace == null) { + throw new RuntimeException("namespace cannot be null"); + } + + if (project == null) { + throw new RuntimeException("project cannot be null"); + } + + String projectPath = null; + try { + projectPath = URLEncoder.encode(namespace + "/" + project, "UTF-8"); + } catch (UnsupportedEncodingException uee) { + throw (new GitLabApiException(uee)); + } + + Form formData = new GitLabApiForm().withParam("statistics", statistics); + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectPath); + return (response.readEntity(Project.class)); + } + /** * Get an Optional instance with the value for the specific project, which is owned by the authentication user. * From a83b6438263571649da852e11a99c91a500ca6c4 Mon Sep 17 00:00:00 2001 From: renjie <1354334940@qq.com> Date: Thu, 21 Jun 2018 14:45:54 +0800 Subject: [PATCH 3/8] add two getRepositoryArchive() apis with param "format" --- .../java/org/gitlab4j/api/RepositoryApi.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/RepositoryApi.java b/src/main/java/org/gitlab4j/api/RepositoryApi.java index 45732547e..21867fcbf 100644 --- a/src/main/java/org/gitlab4j/api/RepositoryApi.java +++ b/src/main/java/org/gitlab4j/api/RepositoryApi.java @@ -425,6 +425,26 @@ public InputStream getRepositoryArchive(Integer projectId, String sha) throws Gi return (response.readEntity(InputStream.class)); } + /** + * Get an archive of the complete repository by SHA (optional). + * + * GET /projects/:id/repository/archive + * + * @param projectId the ID of the project + * @param sha the SHA of the archive to get + * @param format The archive format. Default is tar.gz. Options are tar.gz, tar.bz2, tbz, tbz2, + * tb2, bz2, tar, zip + * @return an input stream that can be used to save as a file + * or to read the content of the archive + * @throws GitLabApiException if any exception occurs + */ + public InputStream getRepositoryArchive(Integer projectId, String sha, String format) throws GitLabApiException { + Form formData = new GitLabApiForm().withParam("sha", sha).withParam("format", format); + Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD, + "projects", projectId, "repository", "archive"); + return (response.readEntity(InputStream.class)); + } + /** * Get an archive of the complete repository by SHA (optional) and saves to the specified directory. * If the archive already exists in the directory it will be overwritten. @@ -460,6 +480,43 @@ public File getRepositoryArchive(Integer projectId, String sha, File directory) } } + /** + * Get an archive of the complete repository by SHA (optional) and saves to the specified directory. + * If the archive already exists in the directory it will be overwritten. + * + * GET /projects/:id/repository/archive + * + * @param projectId the ID of the project + * @param sha the SHA of the archive to get + * @param directory the File instance of the directory to save the archive to, if null will use "java.io.tmpdir" + * @param format The archive format. Default is tar.gz. Options are tar.gz, tar.bz2, tbz, tbz2, + * tb2, bz2, tar, zip + * @return a File instance pointing to the downloaded instance + * @throws GitLabApiException if any exception occurs + */ + public File getRepositoryArchive(Integer projectId, String sha, File directory, String format) throws GitLabApiException { + + Form formData = new GitLabApiForm().withParam("sha", sha).withParam("format", format); + Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD, + "projects", projectId, "repository", "archive"); + + try { + + if (directory == null) + directory = new File(System.getProperty("java.io.tmpdir")); + + String filename = FileUtils.getFilenameFromContentDisposition(response); + File file = new File(directory, filename); + + InputStream in = response.readEntity(InputStream.class); + Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING); + return (file); + + } catch (IOException ioe) { + throw new GitLabApiException(ioe); + } + } + /** * Compare branches, tags or commits. This can be accessed without authentication * if the repository is publicly accessible. From c94e2c8f4ecf7153a411ab790f0636704e0dc23d Mon Sep 17 00:00:00 2001 From: renjie Date: Wed, 27 Jun 2018 15:05:16 +0800 Subject: [PATCH 4/8] 1.added a pom dependency: com.alibaba fastjson 1.2.47 2.added a method to get languages used in a project. --- pom.xml | 5 +++++ .../java/org/gitlab4j/api/ProjectApi.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/pom.xml b/pom.xml index 844961bd1..010fa0f8e 100644 --- a/pom.xml +++ b/pom.xml @@ -206,6 +206,11 @@ javax.activation 1.2.0 + + com.alibaba + fastjson + 1.2.47 + com.fasterxml.jackson.jaxrs diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java index 1aa6686e7..302756aee 100644 --- a/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -23,6 +23,7 @@ package org.gitlab4j.api; +import com.alibaba.fastjson.JSONObject; import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -2176,4 +2177,23 @@ public Project unstarProject(Object projectIdOrPath) throws GitLabApiException { Response response = post(expectedStatus, (Form) null, "projects", getProjectIdOrPath(projectIdOrPath), "unstar"); return (response.readEntity(Project.class)); } + + /** + * Get languages used in a project with percentage value. + * + * Get /projects/:id/languages + * + * @param projectId the ID of the project + * @return a JSONObject instance with the language info + * @throws GitLabApiException if any exception occurs + */ + public JSONObject getProjectLanguage(Integer projectId) throws GitLabApiException { + + if (projectId == null) { + throw new RuntimeException("projectId cannot be null"); + } + + Response response = get(Response.Status.OK, getDefaultPerPageParam(),"projects", projectId, "languages"); + return (response.readEntity(JSONObject.class)); + } } \ No newline at end of file From 3ee5af9798701077d63402997155704a207c9439 Mon Sep 17 00:00:00 2001 From: renjie Date: Wed, 27 Jun 2018 15:37:27 +0800 Subject: [PATCH 5/8] added markdown transformed method and model --- .../org/gitlab4j/api/RepositoryFileApi.java | 26 +++++++++++++++++-- .../org/gitlab4j/api/models/Markdown.java | 20 ++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/gitlab4j/api/models/Markdown.java diff --git a/src/main/java/org/gitlab4j/api/RepositoryFileApi.java b/src/main/java/org/gitlab4j/api/RepositoryFileApi.java index caf2f066a..de21d752d 100644 --- a/src/main/java/org/gitlab4j/api/RepositoryFileApi.java +++ b/src/main/java/org/gitlab4j/api/RepositoryFileApi.java @@ -11,6 +11,8 @@ import javax.ws.rs.core.Response; import org.gitlab4j.api.GitLabApi.ApiVersion; +import org.gitlab4j.api.models.Branch; +import org.gitlab4j.api.models.Markdown; import org.gitlab4j.api.models.RepositoryFile; /** @@ -93,7 +95,7 @@ public RepositoryFile createFile(RepositoryFile file, Integer projectId, String } else { response = post(Response.Status.CREATED, formData, "projects", projectId, "repository", "files", urlEncode(file.getFilePath())); } - + return (response.readEntity(RepositoryFile.class)); } @@ -123,7 +125,7 @@ public RepositoryFile updateFile(RepositoryFile file, Integer projectId, String } else { response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "files", urlEncode(file.getFilePath())); } - + return (response.readEntity(RepositoryFile.class)); } @@ -215,6 +217,26 @@ public InputStream getRawFile(Integer projectId, String commitOrBranchName, Stri return (response.readEntity(InputStream.class)); } + /** + * Render an arbitrary Markdown document. + * + * POST /api/v4/markdown + * + * @param text text to be transformed + * @return a Markdown instance with transformed info + * @throws GitLabApiException if any exception occurs + */ + public Markdown getMarkdown(String text) throws GitLabApiException { + + if(!isApiVersion(ApiVersion.V4)){ + throw new GitLabApiException("Api version must be v4"); + } + + Form formData = new GitLabApiForm().withParam("text", text, true); + Response response = post(Response.Status.OK, formData.asMap(), "markdown"); + return (response.readEntity(Markdown.class)); + } + private Form createForm(RepositoryFile file, String branchName, String commitMessage) { Form form = new Form(); diff --git a/src/main/java/org/gitlab4j/api/models/Markdown.java b/src/main/java/org/gitlab4j/api/models/Markdown.java new file mode 100644 index 000000000..74e674c29 --- /dev/null +++ b/src/main/java/org/gitlab4j/api/models/Markdown.java @@ -0,0 +1,20 @@ +package org.gitlab4j.api.models; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class Markdown { + + private String html; + + public String getHtml() { + return html; + } + + public void setHtml(String html) { + this.html = html; + } +} From ff6accd46ae6b813217eca0168f9b71c6591bfed Mon Sep 17 00:00:00 2001 From: renjie Date: Wed, 27 Jun 2018 15:50:59 +0800 Subject: [PATCH 6/8] added license template method and model --- .../org/gitlab4j/api/RepositoryFileApi.java | 47 ++++++++ .../gitlab4j/api/models/LicenseTemplate.java | 111 ++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 src/main/java/org/gitlab4j/api/models/LicenseTemplate.java diff --git a/src/main/java/org/gitlab4j/api/RepositoryFileApi.java b/src/main/java/org/gitlab4j/api/RepositoryFileApi.java index de21d752d..d31da6c4e 100644 --- a/src/main/java/org/gitlab4j/api/RepositoryFileApi.java +++ b/src/main/java/org/gitlab4j/api/RepositoryFileApi.java @@ -6,13 +6,17 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; +import java.util.List; import javax.ws.rs.core.Form; +import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Branch; +import org.gitlab4j.api.models.LicenseTemplate; import org.gitlab4j.api.models.Markdown; +import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.RepositoryFile; /** @@ -237,6 +241,49 @@ public Markdown getMarkdown(String text) throws GitLabApiException { return (response.readEntity(Markdown.class)); } + /** + * Get all license templates. + * + * GET /licenses + * + * @return a list of LicenseTemplate instances + * @throws GitLabApiException if any exception occurs + */ + public List getAllLicenseTemplates() throws GitLabApiException { + GitLabApiForm formData = null; + Response response = get(Response.Status.OK, formData.asMap(), "licenses"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get popular license templates. + * + * GET /licenses + * + * @return a list of LicenseTemplate instances + * @throws GitLabApiException if any exception occurs + */ + public List getPopularLicenseTemplates() throws GitLabApiException { + Form formData = new GitLabApiForm().withParam("popular", true, true); + Response response = get(Response.Status.OK, formData.asMap(), "licenses"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get a single license template. + * + * GET /licenses + * + * @param key The key of the license template + * @return a LicenseTemplate instance + * @throws GitLabApiException if any exception occurs + */ + public LicenseTemplate getSingleLicenseTemplate(String key) throws GitLabApiException { + GitLabApiForm formData = null; + Response response = get(Response.Status.OK, formData.asMap(), "licenses", key); + return (response.readEntity(LicenseTemplate.class)); + } + private Form createForm(RepositoryFile file, String branchName, String commitMessage) { Form form = new Form(); diff --git a/src/main/java/org/gitlab4j/api/models/LicenseTemplate.java b/src/main/java/org/gitlab4j/api/models/LicenseTemplate.java new file mode 100644 index 000000000..d8feafa9d --- /dev/null +++ b/src/main/java/org/gitlab4j/api/models/LicenseTemplate.java @@ -0,0 +1,111 @@ +package org.gitlab4j.api.models; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class LicenseTemplate { + + private String key; + private String name; + private String nickname; + private boolean featured; + private String htmlUrl; + private String sourceUrl; + private String description; + private List conditions; + private List permissions; + private List limitations; + private String content; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getNickname() { + return nickname; + } + + public void setNickname(String nickname) { + this.nickname = nickname; + } + + public boolean isFeatured() { + return featured; + } + + public void setFeatured(boolean featured) { + this.featured = featured; + } + + public String getHtmlUrl() { + return htmlUrl; + } + + public void setHtmlUrl(String htmlUrl) { + this.htmlUrl = htmlUrl; + } + + public String getSourceUrl() { + return sourceUrl; + } + + public void setSourceUrl(String sourceUrl) { + this.sourceUrl = sourceUrl; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List getConditions() { + return conditions; + } + + public void setConditions(List conditions) { + this.conditions = conditions; + } + + public List getPermissions() { + return permissions; + } + + public void setPermissions(List permissions) { + this.permissions = permissions; + } + + public List getLimitations() { + return limitations; + } + + public void setLimitations(List limitations) { + this.limitations = limitations; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} From 12ef0b72b16ca8b628b9c1420705392a2da44aba Mon Sep 17 00:00:00 2001 From: renjie Date: Thu, 28 Jun 2018 10:36:47 +0800 Subject: [PATCH 7/8] Removed the dependency on com.alibaba.fastjson. Added 2 classes and moved the corresponding methods to. Added 2 members LicensesApi & MarkdownApi to GitLabApi.java. Repaired getProjectLanguage(Integer projectId) as requested. --- pom.xml | 5 -- src/main/java/org/gitlab4j/api/GitLabApi.java | 40 ++++++++++++ .../java/org/gitlab4j/api/LicensesApi.java | 60 ++++++++++++++++++ .../java/org/gitlab4j/api/MarkdownApi.java | 37 +++++++++++ .../java/org/gitlab4j/api/ProjectApi.java | 11 ++-- .../org/gitlab4j/api/RepositoryFileApi.java | 63 ------------------- 6 files changed, 143 insertions(+), 73 deletions(-) create mode 100644 src/main/java/org/gitlab4j/api/LicensesApi.java create mode 100644 src/main/java/org/gitlab4j/api/MarkdownApi.java diff --git a/pom.xml b/pom.xml index cb713620b..014f7f77b 100644 --- a/pom.xml +++ b/pom.xml @@ -206,11 +206,6 @@ javax.activation 1.2.0 - - com.alibaba - fastjson - 1.2.47 - com.fasterxml.jackson.jaxrs diff --git a/src/main/java/org/gitlab4j/api/GitLabApi.java b/src/main/java/org/gitlab4j/api/GitLabApi.java index dc6450d0b..7ed771a1a 100644 --- a/src/main/java/org/gitlab4j/api/GitLabApi.java +++ b/src/main/java/org/gitlab4j/api/GitLabApi.java @@ -53,6 +53,8 @@ public String getApiNamespace() { private GroupApi groupApi; private HealthCheckApi healthCheckApi; private IssuesApi issuesApi; + private LicensesApi licensesApi; + private MarkdownApi markdownApi; private MergeRequestApi mergeRequestApi; private MilestonesApi milestonesApi; private NamespaceApi namespaceApi; @@ -951,6 +953,44 @@ public LabelsApi getLabelsApi() { return (labelsApi); } + /** + * Gets the LicensesApi instance owned by this GitLabApi instance. The LicensesApi is used + * to perform all license related API calls. + * + * @return the LicensesApi instance owned by this GitLabApi instance + */ + public LicensesApi getLicensesApi() { + + if (licensesApi == null) { + synchronized (this) { + if (licensesApi == null) { + licensesApi = new LicensesApi(this); + } + } + } + + return (licensesApi); + } + + /** + * Gets the MarkdownApi instance owned by this GitLabApi instance. The MarkdownApi is used + * to perform all markdown related API calls. + * + * @return the MarkdownApi instance owned by this GitLabApi instance + */ + public MarkdownApi getMarkdownApi() { + + if (markdownApi == null) { + synchronized (this) { + if (markdownApi == null) { + markdownApi = new MarkdownApi(this); + } + } + } + + return (markdownApi); + } + /** * Gets the MergeRequestApi instance owned by this GitLabApi instance. The MergeRequestApi is used * to perform all merge request related API calls. diff --git a/src/main/java/org/gitlab4j/api/LicensesApi.java b/src/main/java/org/gitlab4j/api/LicensesApi.java new file mode 100644 index 000000000..90a13ee1e --- /dev/null +++ b/src/main/java/org/gitlab4j/api/LicensesApi.java @@ -0,0 +1,60 @@ +package org.gitlab4j.api; + +import java.util.List; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.Response; +import org.gitlab4j.api.models.LicenseTemplate; + +/** + * This class provides an entry point to all the GitLab API licenses calls. + */ +public class LicensesApi extends AbstractApi { + + public LicensesApi(GitLabApi gitLabApi) { + super(gitLabApi); + } + + /** + * Get all license templates. + * + * GET /licenses + * + * @return a list of LicenseTemplate instances + * @throws GitLabApiException if any exception occurs + */ + public List getAllLicenseTemplates() throws GitLabApiException { + GitLabApiForm formData = null; + Response response = get(Response.Status.OK, formData.asMap(), "licenses"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get popular license templates. + * + * GET /licenses + * + * @return a list of LicenseTemplate instances + * @throws GitLabApiException if any exception occurs + */ + public List getPopularLicenseTemplates() throws GitLabApiException { + Form formData = new GitLabApiForm().withParam("popular", true, true); + Response response = get(Response.Status.OK, formData.asMap(), "licenses"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get a single license template. + * + * GET /licenses + * + * @param key The key of the license template + * @return a LicenseTemplate instance + * @throws GitLabApiException if any exception occurs + */ + public LicenseTemplate getSingleLicenseTemplate(String key) throws GitLabApiException { + GitLabApiForm formData = null; + Response response = get(Response.Status.OK, formData.asMap(), "licenses", key); + return (response.readEntity(LicenseTemplate.class)); + } +} \ No newline at end of file diff --git a/src/main/java/org/gitlab4j/api/MarkdownApi.java b/src/main/java/org/gitlab4j/api/MarkdownApi.java new file mode 100644 index 000000000..2e9b864c0 --- /dev/null +++ b/src/main/java/org/gitlab4j/api/MarkdownApi.java @@ -0,0 +1,37 @@ +package org.gitlab4j.api; + +import javax.ws.rs.core.Form; +import javax.ws.rs.core.Response; +import org.gitlab4j.api.GitLabApi.ApiVersion; +import org.gitlab4j.api.models.Markdown; + +/** + * This class provides an entry point to all the GitLab API markdown calls. + */ +public class MarkdownApi extends AbstractApi { + + public MarkdownApi(GitLabApi gitLabApi) { + super(gitLabApi); + } + + /** + * Render an arbitrary Markdown document. + * + * POST /api/v4/markdown + * + * @param text text to be transformed + * @return a Markdown instance with transformed info + * @throws GitLabApiException if any exception occurs + * @since GitLab 11.0 + */ + public Markdown getMarkdown(String text) throws GitLabApiException { + + if(!isApiVersion(ApiVersion.V4)){ + throw new GitLabApiException("Api version must be v4"); + } + + Form formData = new GitLabApiForm().withParam("text", text, true); + Response response = post(Response.Status.OK, formData.asMap(), "markdown"); + return (response.readEntity(Markdown.class)); + } +} \ No newline at end of file diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java index 302756aee..9172cf7c5 100644 --- a/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -23,12 +23,12 @@ package org.gitlab4j.api; -import com.alibaba.fastjson.JSONObject; import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.Optional; import javax.ws.rs.core.Form; @@ -2184,16 +2184,17 @@ public Project unstarProject(Object projectIdOrPath) throws GitLabApiException { * Get /projects/:id/languages * * @param projectId the ID of the project - * @return a JSONObject instance with the language info + * @return a Map instance with the language as the key and the percentage as the value * @throws GitLabApiException if any exception occurs + * @since GitLab 10.8 */ - public JSONObject getProjectLanguage(Integer projectId) throws GitLabApiException { + public Map getProjectLanguages(Integer projectId) throws GitLabApiException { if (projectId == null) { throw new RuntimeException("projectId cannot be null"); } - Response response = get(Response.Status.OK, getDefaultPerPageParam(),"projects", projectId, "languages"); - return (response.readEntity(JSONObject.class)); + Response response = get(Response.Status.OK, null, "projects", projectId, "languages"); + return (response.readEntity(new GenericType>() {})); } } \ No newline at end of file diff --git a/src/main/java/org/gitlab4j/api/RepositoryFileApi.java b/src/main/java/org/gitlab4j/api/RepositoryFileApi.java index d31da6c4e..90582a0a7 100644 --- a/src/main/java/org/gitlab4j/api/RepositoryFileApi.java +++ b/src/main/java/org/gitlab4j/api/RepositoryFileApi.java @@ -221,69 +221,6 @@ public InputStream getRawFile(Integer projectId, String commitOrBranchName, Stri return (response.readEntity(InputStream.class)); } - /** - * Render an arbitrary Markdown document. - * - * POST /api/v4/markdown - * - * @param text text to be transformed - * @return a Markdown instance with transformed info - * @throws GitLabApiException if any exception occurs - */ - public Markdown getMarkdown(String text) throws GitLabApiException { - - if(!isApiVersion(ApiVersion.V4)){ - throw new GitLabApiException("Api version must be v4"); - } - - Form formData = new GitLabApiForm().withParam("text", text, true); - Response response = post(Response.Status.OK, formData.asMap(), "markdown"); - return (response.readEntity(Markdown.class)); - } - - /** - * Get all license templates. - * - * GET /licenses - * - * @return a list of LicenseTemplate instances - * @throws GitLabApiException if any exception occurs - */ - public List getAllLicenseTemplates() throws GitLabApiException { - GitLabApiForm formData = null; - Response response = get(Response.Status.OK, formData.asMap(), "licenses"); - return (response.readEntity(new GenericType>() {})); - } - - /** - * Get popular license templates. - * - * GET /licenses - * - * @return a list of LicenseTemplate instances - * @throws GitLabApiException if any exception occurs - */ - public List getPopularLicenseTemplates() throws GitLabApiException { - Form formData = new GitLabApiForm().withParam("popular", true, true); - Response response = get(Response.Status.OK, formData.asMap(), "licenses"); - return (response.readEntity(new GenericType>() {})); - } - - /** - * Get a single license template. - * - * GET /licenses - * - * @param key The key of the license template - * @return a LicenseTemplate instance - * @throws GitLabApiException if any exception occurs - */ - public LicenseTemplate getSingleLicenseTemplate(String key) throws GitLabApiException { - GitLabApiForm formData = null; - Response response = get(Response.Status.OK, formData.asMap(), "licenses", key); - return (response.readEntity(LicenseTemplate.class)); - } - private Form createForm(RepositoryFile file, String branchName, String commitMessage) { Form form = new Form(); From 524b50b6b5d1a8c1e9f7f72deb2083a8f04fe148 Mon Sep 17 00:00:00 2001 From: renjie Date: Thu, 28 Jun 2018 10:41:02 +0800 Subject: [PATCH 8/8] Restored RepositoryFileApi --- src/main/java/org/gitlab4j/api/RepositoryFileApi.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/RepositoryFileApi.java b/src/main/java/org/gitlab4j/api/RepositoryFileApi.java index 90582a0a7..d6058e5a1 100644 --- a/src/main/java/org/gitlab4j/api/RepositoryFileApi.java +++ b/src/main/java/org/gitlab4j/api/RepositoryFileApi.java @@ -6,17 +6,11 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; -import java.util.List; import javax.ws.rs.core.Form; -import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.gitlab4j.api.GitLabApi.ApiVersion; -import org.gitlab4j.api.models.Branch; -import org.gitlab4j.api.models.LicenseTemplate; -import org.gitlab4j.api.models.Markdown; -import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.RepositoryFile; /** @@ -243,4 +237,4 @@ private Form createForm(RepositoryFile file, String branchName, String commitMes addFormParam(form, "commit_message", commitMessage, true); return (form); } -} +} \ No newline at end of file