use of org.gitlab4j.api.models.Project in project catma by forTEXT.
the class GitTagsetHandlerTest method tearDown.
@After
public void tearDown() throws Exception {
if (this.directoriesToDeleteOnTearDown.size() > 0) {
for (File dir : this.directoriesToDeleteOnTearDown) {
FileUtils.deleteDirectory(dir);
}
this.directoriesToDeleteOnTearDown.clear();
}
if (this.tagsetReposToDeleteOnTearDown.size() > 0) {
for (String tagsetId : this.tagsetReposToDeleteOnTearDown) {
String tagsetRepoName = GitTagsetHandler.getTagsetRepositoryName(tagsetId);
List<Project> projects = this.gitLabServerManager.getAdminGitLabApi().getProjectApi().getProjects(tagsetRepoName);
// this getProjects overload does a search
for (Project project : projects) {
this.gitLabServerManager.deleteRepository(project.getId());
}
await().until(() -> this.gitLabServerManager.getAdminGitLabApi().getProjectApi().getProjects().isEmpty());
}
this.tagsetReposToDeleteOnTearDown.clear();
}
if (this.projectsToDeleteOnTearDown.size() > 0) {
GitProjectManager gitProjectHandler = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
for (String projectId : this.projectsToDeleteOnTearDown) {
gitProjectHandler.delete(projectId);
}
this.projectsToDeleteOnTearDown.clear();
}
// delete the GitLab user that the GitLabServerManager constructor in setUp would have
// created - see GitLabServerManagerTest tearDown() for more info
User user = this.gitLabServerManager.getGitLabUser();
this.gitLabServerManager.getAdminGitLabApi().getUserApi().deleteUser(user.getId());
GitLabServerManagerTest.awaitUserDeleted(this.gitLabServerManager.getAdminGitLabApi().getUserApi(), user.getId());
}
use of org.gitlab4j.api.models.Project in project catma by forTEXT.
the class GitLabServerManagerTest method createRepository.
@Test
public void createRepository() throws Exception {
String randomRepoName = Randomizer.getRepoName();
IRemoteGitServerManager.CreateRepositoryResponse createRepositoryResponse = this.serverManager.createRepository(randomRepoName, null);
this.repositoriesToDeleteOnTearDown.add(createRepositoryResponse.repositoryId);
assertNotNull(createRepositoryResponse);
assert createRepositoryResponse.repositoryId > 0;
assertNotNull(createRepositoryResponse.repositoryHttpUrl);
assertNull(createRepositoryResponse.groupPath);
Project project = this.serverManager.getAdminGitLabApi().getProjectApi().getProject(createRepositoryResponse.repositoryId);
assertNotNull(project);
assertEquals(randomRepoName, project.getName());
assertEquals(this.serverManager.getGitLabUser().getId(), project.getOwner().getId());
}
use of org.gitlab4j.api.models.Project in project catma by forTEXT.
the class GitlabManagerRestricted method createRepository.
@Override
public CreateRepositoryResponse createRepository(String name, String path, String groupPath) throws IOException {
GroupApi groupApi = restrictedGitLabApi.getGroupApi();
ProjectApi projectApi = restrictedGitLabApi.getProjectApi();
try {
Group group = groupApi.getGroup(groupPath);
Namespace namespace = new Namespace();
namespace.setId(group.getId());
Project project = new Project();
project.setName(name);
project.setNamespace(namespace);
if (StringUtils.isNotEmpty(path)) {
project.setPath(path);
}
project = projectApi.createProject(project);
return new CreateRepositoryResponse(groupPath, project.getId(), GitlabUtils.rewriteGitLabServerUrl(project.getHttpUrlToRepo()));
} catch (GitLabApiException e) {
throw new IOException("Failed to create remote Git repository", e);
}
}
use of org.gitlab4j.api.models.Project in project catma by forTEXT.
the class GitlabManagerRestricted method getProjectRootRepositoryUrl.
@Override
public String getProjectRootRepositoryUrl(ProjectReference projectReference) throws IOException {
try {
ProjectApi projectApi = restrictedGitLabApi.getProjectApi();
Project rootProject = projectApi.getProject(projectReference.getProjectId(), GitProjectManager.getProjectRootRepositoryName(projectReference.getProjectId()));
return GitlabUtils.rewriteGitLabServerUrl(rootProject.getHttpUrlToRepo());
} catch (GitLabApiException e) {
throw new IOException("Failed to load Project's Root Repository URL: " + GitProjectManager.getProjectRootRepositoryName(projectReference.getProjectId()), e);
}
}
use of org.gitlab4j.api.models.Project 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