Search in sources :

Example 16 with Project

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());
}
Also used : Project(org.gitlab4j.api.models.Project) User(org.gitlab4j.api.models.User) File(java.io.File) After(org.junit.After)

Example 17 with Project

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());
}
Also used : Project(org.gitlab4j.api.models.Project) IRemoteGitServerManager(de.catma.repository.git.interfaces.IRemoteGitServerManager) Test(org.junit.Test)

Example 18 with Project

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);
    }
}
Also used : Group(org.gitlab4j.api.models.Group) Project(org.gitlab4j.api.models.Project) GroupApi(org.gitlab4j.api.GroupApi) ProjectApi(org.gitlab4j.api.ProjectApi) CreateRepositoryResponse(de.catma.repository.git.CreateRepositoryResponse) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Namespace(org.gitlab4j.api.models.Namespace)

Example 19 with Project

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);
    }
}
Also used : Project(org.gitlab4j.api.models.Project) ProjectApi(org.gitlab4j.api.ProjectApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Example 20 with Project

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);
    }
}
Also used : Status(org.gitlab4j.api.models.ImportStatus.Status) ForkStatus(de.catma.project.ForkStatus) Project(org.gitlab4j.api.models.Project) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Aggregations

Project (org.gitlab4j.api.models.Project)27 GitLabApiException (org.gitlab4j.api.GitLabApiException)18 IOException (java.io.IOException)12 GitLabApi (org.gitlab4j.api.GitLabApi)8 Group (org.gitlab4j.api.models.Group)6 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)5 Workflow (com.tremolosecurity.provisioning.core.Workflow)5 GitlabUserProvider (com.tremolosecurity.unison.gitlab.provisioning.targets.GitlabUserProvider)5 GitMember (de.catma.repository.git.GitMember)4 ArrayList (java.util.ArrayList)4 EventBus (com.google.common.eventbus.EventBus)3 ItemDescription (de.bonndan.nivio.input.dto.ItemDescription)3 BackgroundService (de.catma.backgroundservice.BackgroundService)3 ForkStatus (de.catma.project.ForkStatus)3 CreateRepositoryResponse (de.catma.repository.git.CreateRepositoryResponse)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3