Skip to content

Commit 86e8bdc

Browse files
committed
Add project Template list (#1127)
1 parent dff8509 commit 86e8bdc

File tree

7 files changed

+113
-0
lines changed

7 files changed

+113
-0
lines changed

gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
import org.gitlab4j.api.models.UploadedFile;
7272
import org.gitlab4j.api.models.Variable;
7373
import org.gitlab4j.api.models.Visibility;
74+
import org.gitlab4j.api.models.ProjectTemplate;
75+
import org.gitlab4j.api.models.ProjectTemplateType;
7476
import org.gitlab4j.models.Constants;
7577
import org.gitlab4j.models.utils.ISO8601;
7678

@@ -4774,4 +4776,16 @@ public List<Iteration> listProjectIterations(Object projectIdOrPath, IterationFi
47744776
get(Response.Status.OK, queryParams, "projects", getProjectIdOrPath(projectIdOrPath), "iterations");
47754777
return (response.readEntity(new GenericType<List<Iteration>>() {}));
47764778
}
4779+
4780+
public List<ProjectTemplate> getProjectTemplates(Object projectIdOrPath, ProjectTemplateType type)
4781+
throws GitLabApiException {
4782+
Response response = get(
4783+
Response.Status.OK,
4784+
null,
4785+
"projects",
4786+
getProjectIdOrPath(projectIdOrPath),
4787+
"templates",
4788+
type.toString());
4789+
return (response.readEntity(new GenericType<List<ProjectTemplate>>() {}));
4790+
}
47774791
}

gitlab4j-api/src/test/java/org/gitlab4j/api/TestProjectApi.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
import org.gitlab4j.api.models.User;
5757
import org.gitlab4j.api.models.Variable;
5858
import org.gitlab4j.api.models.Visibility;
59+
import org.gitlab4j.api.models.ProjectTemplate;
60+
import org.gitlab4j.api.models.ProjectTemplateType;
5961
import org.gitlab4j.models.Constants;
6062
import org.junit.jupiter.api.AfterAll;
6163
import org.junit.jupiter.api.BeforeAll;
@@ -1084,4 +1086,17 @@ public void testRotateProjectAccessToken() throws GitLabApiException {
10841086
// assertTrue(gitLabApi.getProjectApi().getProjectAccessToken(testProject.getId(),
10851087
// token.getId()).isRevoked());
10861088
}
1089+
1090+
@Test
1091+
public void testProjectTemplates() throws GitLabApiException {
1092+
1093+
assumeTrue(testProject != null);
1094+
1095+
// Act
1096+
List<ProjectTemplate> members =
1097+
gitLabApi.getProjectApi().getProjectTemplates(testProject, ProjectTemplateType.LICENSES);
1098+
1099+
// Assert
1100+
assertNotNull(members);
1101+
}
10871102
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.gitlab4j.api.models;
2+
3+
import org.gitlab4j.models.utils.JacksonJson;
4+
5+
import java.io.Serializable;
6+
7+
public class ProjectTemplate implements Serializable {
8+
private static final long serialVersionUID = 1L;
9+
10+
private String key;
11+
private String name;
12+
13+
public String getKey() {
14+
return key;
15+
}
16+
17+
public void setKey(String key) {
18+
this.key = key;
19+
}
20+
21+
public String getName() {
22+
return name;
23+
}
24+
25+
public void setName(String name) {
26+
this.name = name;
27+
}
28+
29+
@Override
30+
public String toString() {
31+
return (JacksonJson.toJsonString(this));
32+
}
33+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.gitlab4j.api.models;
2+
3+
public class ProjectTemplateDetail extends ProjectTemplate {
4+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.gitlab4j.api.models;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
import org.gitlab4j.models.utils.JacksonJsonEnumHelper;
6+
7+
public enum ProjectTemplateType {
8+
DOCKERFILES,
9+
GITIGNORES,
10+
GITLAB_CI_YMLS,
11+
LICENSES,
12+
ISSUES,
13+
MERGE_REQUESTS;
14+
15+
private static final JacksonJsonEnumHelper<ProjectTemplateType> enumHelper = new JacksonJsonEnumHelper<>(ProjectTemplateType.class);
16+
17+
@JsonCreator
18+
public static ProjectTemplateType forValue(String value) {
19+
return enumHelper.forValue(value);
20+
}
21+
22+
@JsonValue
23+
public String toValue() {
24+
return (enumHelper.toString(this));
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return (enumHelper.toString(this));
30+
}
31+
}

gitlab4j-models/src/test/java/org/gitlab4j/models/TestGitLabApiBeans.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ public void testProjectApprovalsCofig() throws Exception {
496496
assertTrue(compareJson(approvalsConfig, "project-approvals-config.json"));
497497
}
498498

499+
@Test
500+
public void testProjectTemplates() throws Exception {
501+
List<ProjectTemplate> projectTemplates = unmarshalResourceList(ProjectTemplate.class, "project-templates.json");
502+
assertTrue(compareJson(projectTemplates, "project-templates.json"));
503+
}
504+
499505
@Test
500506
public void testProtectedBranch() throws Exception {
501507
ProtectedBranch protectedBranch = unmarshalResource(ProtectedBranch.class, "protected-branch.json");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"key": "epl-1.0",
4+
"name": "Eclipse Public License 1.0"
5+
},
6+
{
7+
"key": "lgpl-3.0",
8+
"name": "GNU Lesser General Public License v3.0"
9+
}
10+
]

0 commit comments

Comments
 (0)