Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 47 additions & 30 deletions gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,7 @@
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;

import org.gitlab4j.api.models.AccessLevel;
import org.gitlab4j.api.models.AccessRequest;
import org.gitlab4j.api.models.ApprovalRule;
import org.gitlab4j.api.models.ApprovalRuleParams;
import org.gitlab4j.api.models.AuditEvent;
import org.gitlab4j.api.models.Badge;
import org.gitlab4j.api.models.CustomAttribute;
import org.gitlab4j.api.models.Event;
import org.gitlab4j.api.models.FileUpload;
import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.Iteration;
import org.gitlab4j.api.models.IterationFilter;
import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.Namespace;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.ProjectAccessToken;
import org.gitlab4j.api.models.ProjectApprovalsConfig;
import org.gitlab4j.api.models.ProjectFetches;
import org.gitlab4j.api.models.ProjectFilter;
import org.gitlab4j.api.models.ProjectGroup;
import org.gitlab4j.api.models.ProjectGroupsFilter;
import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.ProjectUser;
import org.gitlab4j.api.models.PullMirror;
import org.gitlab4j.api.models.PushRules;
import org.gitlab4j.api.models.RemoteMirror;
import org.gitlab4j.api.models.Snippet;
import org.gitlab4j.api.models.UploadedFile;
import org.gitlab4j.api.models.Variable;
import org.gitlab4j.api.models.Visibility;
import org.gitlab4j.api.models.*;
import org.gitlab4j.models.Constants;
import org.gitlab4j.models.utils.ISO8601;

Expand Down Expand Up @@ -4774,4 +4745,50 @@ public List<Iteration> listProjectIterations(Object projectIdOrPath, IterationFi
get(Response.Status.OK, queryParams, "projects", getProjectIdOrPath(projectIdOrPath), "iterations");
return (response.readEntity(new GenericType<List<Iteration>>() {}));
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Javadoc is missing here.

/**
* Get project templates of the specified type.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/templates/:type</code></pre>
*
* @param projectIdOrPath the project in the form of a Long(ID), String(path), or Project instance
* @param type type of the template. Accepted values are: dockerfiles, gitignores, gitlab_ci_ymls, licenses, issues, or merge_requests.
* @return the list of project templates
* @throws GitLabApiException if any exception occurs
*/
public List<ProjectTemplate> getProjectTemplates(Object projectIdOrPath, ProjectTemplateType type)
throws GitLabApiException {
Response response = get(
Response.Status.OK,
null,
"projects",
getProjectIdOrPath(projectIdOrPath),
"templates",
type.toString());
return (response.readEntity(new GenericType<List<ProjectTemplate>>() {}));
}

/**
* Get a specific project template of the specified type.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/templates/:type/:name</code></pre>
*
* @param projectIdOrPath the project in the form of a Long(ID), String(path), or Project instance
* @param type type of the template. Accepted values are: dockerfiles, gitignores, gitlab_ci_ymls, licenses, issues, or merge_requests.
* @param templateName Key of the template
* @return the project template detail
* @throws GitLabApiException if any exception occurs
*/
public ProjectTemplateDetail getProjectTemplate(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Javadoc is missing here.

Object projectIdOrPath, ProjectTemplateType type, String templateName) throws GitLabApiException {
Response response = get(
Response.Status.OK,
null,
"projects",
getProjectIdOrPath(projectIdOrPath),
"templates",
type.toString(),
templateName);
return (response.readEntity(ProjectTemplateDetail.class));
}
}
28 changes: 28 additions & 0 deletions gitlab4j-api/src/test/java/org/gitlab4j/api/TestProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.ProjectFetches;
import org.gitlab4j.api.models.ProjectFilter;
import org.gitlab4j.api.models.ProjectTemplate;
import org.gitlab4j.api.models.ProjectTemplateType;
import org.gitlab4j.api.models.User;
import org.gitlab4j.api.models.Variable;
import org.gitlab4j.api.models.Visibility;
Expand Down Expand Up @@ -1084,4 +1086,30 @@ public void testRotateProjectAccessToken() throws GitLabApiException {
// assertTrue(gitLabApi.getProjectApi().getProjectAccessToken(testProject.getId(),
// token.getId()).isRevoked());
}

@Test
public void testProjectTemplates() throws GitLabApiException {

assumeTrue(testProject != null);

// Act
List<ProjectTemplate> templates =
gitLabApi.getProjectApi().getProjectTemplates(testProject, ProjectTemplateType.LICENSES);

// Assert
assertNotNull(templates);
}

@Test
public void testProjectTemplate() throws GitLabApiException {

assumeTrue(testProject != null);

// Act
ProjectTemplate template =
gitLabApi.getProjectApi().getProjectTemplate(testProject, ProjectTemplateType.LICENSES, "mit");

// Assert
assertNotNull(template);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.gitlab4j.api.models;

import java.io.Serializable;

import org.gitlab4j.models.utils.JacksonJson;

public class ProjectTemplate implements Serializable {
private static final long serialVersionUID = 1L;

private String key;
private String name;

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;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.gitlab4j.api.models;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ProjectTemplateDetail extends ProjectTemplate {

private String nickname;
private Boolean popular;

@JsonProperty("html_url")
private String htmlUrl;

@JsonProperty("source_url")
private String sourceUrl;

private String content;
private String description;
private List<String> conditions;
private List<String> permissions;
private List<String> limitations;

public String getNickname() {
return nickname;
}

public void setNickname(String nickname) {
this.nickname = nickname;
}

public Boolean getPopular() {
return popular;
}

public void setPopular(Boolean popular) {
this.popular = popular;
}

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 getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.gitlab4j.api.models;

import org.gitlab4j.models.utils.JacksonJsonEnumHelper;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum ProjectTemplateType {
DOCKERFILES,
GITIGNORES,
GITLAB_CI_YMLS,
LICENSES,
ISSUES,
MERGE_REQUESTS;

private static final JacksonJsonEnumHelper<ProjectTemplateType> enumHelper =
new JacksonJsonEnumHelper<>(ProjectTemplateType.class);

@JsonCreator
public static ProjectTemplateType forValue(String value) {
return enumHelper.forValue(value);
}

@JsonValue
public String toValue() {
return (enumHelper.toString(this));
}

@Override
public String toString() {
return (enumHelper.toString(this));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,18 @@ public void testProjectApprovalsCofig() throws Exception {
assertTrue(compareJson(approvalsConfig, "project-approvals-config.json"));
}

@Test
public void testProjectTemplates() throws Exception {
List<ProjectTemplate> projectTemplates = unmarshalResourceList(ProjectTemplate.class, "project-templates.json");
assertTrue(compareJson(projectTemplates, "project-templates.json"));
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to add a similar test for ProjectTemplateDetail.java

@Test
public void testProjectTemplate() throws Exception {
ProjectTemplateDetail projectTemplate = unmarshalResource(ProjectTemplateDetail.class, "project-template.json");
assertTrue(compareJson(projectTemplate, "project-template.json"));
}

@Test
public void testProtectedBranch() throws Exception {
ProtectedBranch protectedBranch = unmarshalResource(ProtectedBranch.class, "protected-branch.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"key": "mit",
"name": "MIT License",
"nickname": "nickname",
"popular": true,
"html_url": "http://choosealicense.com/licenses/mit/",
"source_url": "https://opensource.org/licenses/MIT",
"description": "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.",
"conditions": [
"include-copyright"
],
"permissions": [
"commercial-use",
"modifications",
"distribution",
"private-use"
],
"limitations": [
"liability",
"warranty"
],
"content": "MIT License content"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"key": "epl-1.0",
"name": "Eclipse Public License 1.0"
},
{
"key": "lgpl-3.0",
"name": "GNU Lesser General Public License v3.0"
}
]
Loading