From a319e7d6c5f4deb0917d4b516138e377084315da Mon Sep 17 00:00:00 2001 From: jjansen Date: Mon, 25 Oct 2021 11:50:02 +0200 Subject: [PATCH] Create new projects from project template. --- .../java/org/gitlab4j/api/ProjectApi.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java index af89b5200..fe7ebbdb1 100644 --- a/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -1196,6 +1196,30 @@ public Project createProject(String name, Integer namespaceId, String descriptio return (response.readEntity(Project.class)); } + /** + * Create a new project from a template, belonging to the namespace ID. A namespace ID is either a user or group ID. + * + * @param namespaceId the namespace ID to create the project under + * @param projectName the name of the project top create + * @param groupWithProjectTemplatesId Id of the Gitlab Group, which contains the relevant templates. + * @param templateName name of the template to use + * @param visibility Visibility of the new create project + * @return the created project + * @throws GitLabApiException if any exception occurs + */ + public Project createProjectFromTemplate(Integer namespaceId, String projectName, Integer groupWithProjectTemplatesId, String templateName, Visibility visibility) throws GitLabApiException { + GitLabApiForm formData = new GitLabApiForm() + .withParam("namespace_id", namespaceId) + .withParam("name", projectName, true) + .withParam("use_custom_template", true) + .withParam("group_with_project_templates_id", groupWithProjectTemplatesId, true) + .withParam("template_name", templateName, true) + .withParam("visibility", visibility) + ; + Response response = post(Response.Status.CREATED, formData, "projects"); + return (response.readEntity(Project.class)); + } + /** * Updates a project. The following properties on the Project instance * are utilized in the edit of the project, null values are not updated: