use of org.gitlab4j.api.models.ImportStatus.Status in project catma by forTEXT.
the class GitlabManagerRestricted method forkResource.
@Override
public ForkStatus forkResource(String resourceId, String sourceProjectId, String targetProjectId) throws IOException {
try {
Project sourceResourceProject = restrictedGitLabApi.getProjectApi().getProject(sourceProjectId, resourceId);
Optional<Project> optionalTargetResource = restrictedGitLabApi.getProjectApi().getOptionalProject(targetProjectId, resourceId);
if (optionalTargetResource.isPresent()) {
return ForkStatus.resourceAlreadyExists();
}
restrictedGitLabApi.getProjectApi().forkProject(sourceResourceProject, targetProjectId);
Project targetProject = restrictedGitLabApi.getProjectApi().getProject(targetProjectId, resourceId);
Status importStatus = targetProject.getImportStatus();
int tries = 10;
while (importStatus != Status.FINISHED && tries > 0) {
tries--;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
logger.info(String.format("Trying to retrieve forked resource status for %1$s from group %2$s (try %3$d)", resourceId, targetProjectId, 10 - tries));
importStatus = targetProject.getImportStatus();
}
if (importStatus != Status.FINISHED) {
logger.warning(String.format("Status is still '%1$s' and not 'finished'! Trying to continue anyway!", importStatus));
}
return ForkStatus.success();
} catch (GitLabApiException e) {
throw new IOException(String.format("Failed to fork resource %1$s from group %2$s into group %3$s", resourceId, sourceProjectId, targetProjectId), e);
}
}
Aggregations