Skip to content
40 changes: 40 additions & 0 deletions src/main/java/org/gitlab4j/api/GitLabApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/org/gitlab4j/api/LicensesApi.java
Original file line number Diff line number Diff line change
@@ -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<LicenseTemplate> getAllLicenseTemplates() throws GitLabApiException {
GitLabApiForm formData = null;
Response response = get(Response.Status.OK, formData.asMap(), "licenses");
return (response.readEntity(new GenericType<List<LicenseTemplate>>() {}));
}

/**
* Get popular license templates.
*
* GET /licenses
*
* @return a list of LicenseTemplate instances
* @throws GitLabApiException if any exception occurs
*/
public List<LicenseTemplate> 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<List<LicenseTemplate>>() {}));
}

/**
* 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));
}
}
37 changes: 37 additions & 0 deletions src/main/java/org/gitlab4j/api/MarkdownApi.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
21 changes: 21 additions & 0 deletions src/main/java/org/gitlab4j/api/ProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -2176,4 +2177,24 @@ public Project unstarProject(Object projectIdOrPath) throws GitLabApiException {
Response response = post(expectedStatus, (Form) null, "projects", getProjectIdOrPath(projectIdOrPath), "unstar");
return (response.readEntity(Project.class));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to introduce a new type for this, please re-implement getProjectLanguage(Integer projectId) as follows:

    /**
     * Get languages used in a project with percentage value.
     *
     * Get /projects/:id/languages
     *
     * @param projectId the ID of the project
     * @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 Map<String, Float> getProjectLanguages(Integer projectId) throws GitLabApiException {

        if (projectId == null) {
            throw new RuntimeException("projectId cannot be null");
        }

        Response response = get(Response.Status.OK, null, "projects", projectId, "languages");
        return (response.readEntity(new GenericType<Map<String, Float>>() { }));
    }

/**
* Get languages used in a project with percentage value.
*
* Get /projects/:id/languages
*
* @param projectId the ID of the project
* @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 Map<String, Float> getProjectLanguages(Integer projectId) throws GitLabApiException {

if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}

Response response = get(Response.Status.OK, null, "projects", projectId, "languages");
return (response.readEntity(new GenericType<Map<String, Float>>() {}));
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/gitlab4j/api/RepositoryFileApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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));
}

Expand Down Expand Up @@ -123,7 +123,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));
}

Expand Down Expand Up @@ -237,4 +237,4 @@ private Form createForm(RepositoryFile file, String branchName, String commitMes
addFormParam(form, "commit_message", commitMessage, true);
return (form);
}
}
}
111 changes: 111 additions & 0 deletions src/main/java/org/gitlab4j/api/models/LicenseTemplate.java
Original file line number Diff line number Diff line change
@@ -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<String> conditions;
private List<String> permissions;
private List<String> 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<String> getConditions() {
return conditions;
}

public void setConditions(List<String> conditions) {
this.conditions = conditions;
}

public List<String> getPermissions() {
return permissions;
}

public void setPermissions(List<String> permissions) {
this.permissions = permissions;
}

public List<String> getLimitations() {
return limitations;
}

public void setLimitations(List<String> limitations) {
this.limitations = limitations;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}
}
20 changes: 20 additions & 0 deletions src/main/java/org/gitlab4j/api/models/Markdown.java
Original file line number Diff line number Diff line change
@@ -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;
}
}