-
Notifications
You must be signed in to change notification settings - Fork 487
Add project Template list #1127 #1291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
|
|
@@ -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>>() {})); | ||
| } | ||
|
|
||
| /** | ||
| * 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( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
gitlab4j-models/src/main/java/org/gitlab4j/api/models/ProjectTemplate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | ||
| } | ||
| } |
95 changes: 95 additions & 0 deletions
95
gitlab4j-models/src/main/java/org/gitlab4j/api/models/ProjectTemplateDetail.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
gitlab4j-models/src/main/java/org/gitlab4j/api/models/ProjectTemplateType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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")); | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to add a similar test for |
||
| @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"); | ||
|
|
||
23 changes: 23 additions & 0 deletions
23
gitlab4j-models/src/test/resources/org/gitlab4j/models/project-template.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
10 changes: 10 additions & 0 deletions
10
gitlab4j-models/src/test/resources/org/gitlab4j/models/project-templates.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javadoc is missing here.