Skip to content

Commit 2e7cc87

Browse files
author
to5671sc
committed
Add import function with name parameter
1 parent 6c06521 commit 2e7cc87

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

src/main/java/org/gitlab4j/api/ImportExportApi.java

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,98 @@ public ImportStatus startImport(Object namespaceIdOrPath, File exportFile, Strin
246246
return (response.readEntity(ImportStatus.class));
247247
}
248248

249+
/**
250+
* <p>Import an exported project. The following properties on the Project instance
251+
* are utilized in the creation of the new project:</p>
252+
*<ul>
253+
* <li>defaultBranch (optional) - master by default</li>
254+
* <li>description (optional) - short project description</li>
255+
* <li>visibility (optional) - Limit by visibility public, internal, or private</li>
256+
* <li>visibilityLevel (optional)</li>
257+
* <li>issuesEnabled (optional) - Enable issues for this project</li>
258+
* <li>mergeMethod (optional) - Set the merge method used</li>
259+
* <li>mergeRequestsEnabled (optional) - Enable merge requests for this project</li>
260+
* <li>wikiEnabled (optional) - Enable wiki for this project</li>
261+
* <li>snippetsEnabled (optional) - Enable snippets for this project</li>
262+
* <li>jobsEnabled (optional) - Enable jobs for this project</li>
263+
* <li>containerRegistryEnabled (optional) - Enable container registry for this project</li>
264+
* <li>sharedRunnersEnabled (optional) - Enable shared runners for this project</li>
265+
* <li>publicJobs (optional) - If true, jobs can be viewed by non-project-members</li>
266+
* <li>onlyAllowMergeIfPipelineSucceeds (optional) - Set whether merge requests can only be merged with successful jobs</li>
267+
* <li>onlyAllowMergeIfAllDiscussionsAreResolved (optional) - Set whether merge requests can only be merged when all the discussions are resolved</li>
268+
* <li>lfsEnabled (optional) - Enable LFS</li>
269+
* <li>requestAccessEnabled (optional) - Allow users to request member access</li>
270+
* <li>repositoryStorage (optional) - Which storage shard the repository is on. Available only to admins</li>
271+
* <li>approvalsBeforeMerge (optional) - How many approvers should approve merge request by default</li>
272+
* <li>printingMergeRequestLinkEnabled (optional) - Show link to create/view merge request when pushing from the command line</li>
273+
* <li>resolveOutdatedDiffDiscussions (optional) - Automatically resolve merge request diffs discussions on lines changed with a push</li>
274+
* <li>initialize_with_readme (optional) - Initialize project with README file</li>
275+
* <li>packagesEnabled (optional) - Enable or disable mvn packages repository feature</li>
276+
*</ul>
277+
* <pre><code>GitLab Endpoint: POST /projects/import</code></pre>
278+
*
279+
* @param namespaceIdOrPath the ID or path of the namespace that the project will be imported to. Defaults to the current user’s namespace
280+
* @param exportFile the project export file to be imported
281+
* @param path the name and path for the new project
282+
* @param name the name of the project to be imported
283+
* @param overwrite if there is a project with the same path the import will overwrite it. Defaults to false
284+
* @param overrideParams overriding project params, supports all fields defined by the ProjectApi, optional
285+
* @return an Importstatus instance with info for the project being imported to
286+
* @throws GitLabApiException if any exception occurs
287+
*/
288+
public ImportStatus startImport(Object namespaceIdOrPath, File exportFile, String path,String name, Boolean overwrite, Project overrideParams) throws GitLabApiException {
289+
290+
URL url;
291+
try {
292+
url = getApiClient().getApiUrl("projects", "import");
293+
} catch (IOException ioe) {
294+
throw new GitLabApiException(ioe);
295+
}
296+
297+
GitLabApiForm formData = new GitLabApiForm()
298+
.withParam("path", path, true)
299+
.withParam("name", name, true)
300+
.withParam("namespace", namespaceIdOrPath)
301+
.withParam("overwrite", overwrite);
302+
303+
if (overrideParams != null) {
304+
formData.withParam("default_branch", overrideParams.getDefaultBranch())
305+
.withParam("description", overrideParams.getDescription())
306+
.withParam("issues_enabled", overrideParams.getIssuesEnabled())
307+
.withParam("merge_method", overrideParams.getMergeMethod())
308+
.withParam("merge_requests_enabled", overrideParams.getMergeRequestsEnabled())
309+
.withParam("jobs_enabled", overrideParams.getJobsEnabled())
310+
.withParam("wiki_enabled", overrideParams.getUncycloEnabled())
311+
.withParam("container_registry_enabled", overrideParams.getContainerRegistryEnabled())
312+
.withParam("snippets_enabled", overrideParams.getSnippetsEnabled())
313+
.withParam("shared_runners_enabled", overrideParams.getSharedRunnersEnabled())
314+
.withParam("public_jobs", overrideParams.getPublicJobs())
315+
.withParam("visibility_level", overrideParams.getVisibilityLevel())
316+
.withParam("only_allow_merge_if_pipeline_succeeds", overrideParams.getOnlyAllowMergeIfPipelineSucceeds())
317+
.withParam("only_allow_merge_if_all_discussions_are_resolved", overrideParams.getOnlyAllowMergeIfAllDiscussionsAreResolved())
318+
.withParam("lfs_enabled", overrideParams.getLfsEnabled())
319+
.withParam("request_access_enabled", overrideParams.getRequestAccessEnabled())
320+
.withParam("repository_storage", overrideParams.getRepositoryStorage())
321+
.withParam("approvals_before_merge", overrideParams.getApprovalsBeforeMerge())
322+
.withParam("printing_merge_request_link_enabled", overrideParams.getPrintingMergeRequestLinkEnabled())
323+
.withParam("resolve_outdated_diff_discussions", overrideParams.getResolveOutdatedDiffDiscussions())
324+
.withParam("initialize_with_readme", overrideParams.getInitializeWithReadme())
325+
.withParam("packages_enabled", overrideParams.getPackagesEnabled())
326+
.withParam("build_git_strategy", overrideParams.getBuildGitStrategy())
327+
.withParam("build_coverage_regex", overrideParams.getBuildCoverageRegex())
328+
.withParam("squash_option", overrideParams.getSquashOption());
329+
}
330+
331+
Response response = upload(Response.Status.CREATED, "file", exportFile, null, formData, url);
332+
return (response.readEntity(ImportStatus.class));
333+
}
334+
249335
/**
250336
* Get the status of an import.
251337
*
252338
* <pre><code>GitLab Endpoint: GET /projects/:id/import</code></pre>
253339
*
254-
* @param projectIdOrPath the new (imported) project identifier in the form of an Long(ID), String(path), or Project instance
340+
* @param projectIdOrPath the new (imported) project identifier in the form of an Long(ID), String(path), or Project instance
255341
* @return an ImportStatus instance holding information on the import status
256342
* @throws GitLabApiException if any exception occurs
257343
*/

0 commit comments

Comments
 (0)