Search in sources :

Example 11 with Project

use of org.gitlab4j.api.models.Project in project nivio by dedica-team.

the class GitLabRepoHandlerTest method setsLabels.

@Test
void setsLabels() throws MalformedURLException, ExecutionException, InterruptedException, GitLabApiException {
    // given
    Link link = new Link(new URL("https://gitlab.com/bonndan/nivio-private-demo"), "gitlab");
    Project project = new Project();
    project.setDescription("Private repo test");
    project.setOpenIssuesCount(12);
    when(projectApi.getProject(eq("bonndan/nivio-private-demo"))).thenReturn(project);
    when(mrApi.getMergeRequests(eq("bonndan/nivio-private-demo"))).thenReturn(List.of(mock(MergeRequest.class)));
    // when
    ItemDescription description = (ItemDescription) handler.resolve(link).get();
    // then
    assertThat(description.getLabel(RepositoryLinkHandler.DESCRIPTION)).isEqualTo("Private repo test");
    assertThat(description.getLabel(RepositoryLinkHandler.OPEN_ISSUES)).isEqualTo("12");
}
Also used : Project(org.gitlab4j.api.models.Project) ItemDescription(de.bonndan.nivio.input.dto.ItemDescription) Link(de.bonndan.nivio.model.Link) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 12 with Project

use of org.gitlab4j.api.models.Project in project octane-gitlab-service by MicroFocus.

the class GitlabServices method stop.

@PreDestroy
private void stop() {
    try {
        log.info("Destroying GitLab webhooks ...");
        List<Project> projects = isCurrentUserAdmin() ? gitLabApi.getProjectApi().getProjects() : gitLabApi.getProjectApi().getMemberProjects();
        User currentUser = gitLabApi.getUserApi().getCurrentUser();
        for (Project project : projects) {
            if (gitLabApiWrapper.isUserHasPermissionForProject(project, currentUser)) {
                deleteWebHooks(project.getId());
            }
        }
    } catch (Exception e) {
        log.warn("Failed to destroy GitLab webhooks", e);
    }
}
Also used : Project(org.gitlab4j.api.models.Project) User(org.gitlab4j.api.models.User) MalformedURLException(java.net.MalformedURLException) GitLabApiException(org.gitlab4j.api.GitLabApiException) PreDestroy(javax.annotation.PreDestroy)

Example 13 with Project

use of org.gitlab4j.api.models.Project in project octane-gitlab-service by MicroFocus.

the class GitlabServices method getJobList.

CIJobsList getJobList() {
    CIJobsList ciJobsList = dtoFactory.newDTO(CIJobsList.class);
    List<PipelineNode> list = new ArrayList<>();
    String projectNames = "";
    try {
        ProjectFilter filter = new ProjectFilter();
        filter.withMinAccessLevel(AccessLevel.MAINTAINER);
        List<Project> projectsFilters = gitLabApi.getProjectApi().getProjects(filter);
        log.info("There are only " + projectsFilters.size() + " projects with access level => MAINTAINER for the integrated user");
        for (Project project : projectsFilters) {
            try {
                ParsedPath parseProject = new ParsedPath(project, gitLabApi);
                PipelineNode buildConf;
                if (parseProject.isMultiBranch()) {
                    buildConf = dtoFactory.newDTO(PipelineNode.class).setJobCiId(parseProject.getJobCiId(true)).setName(project.getNameWithNamespace()).setMultiBranchType(MultiBranchType.MULTI_BRANCH_PARENT);
                } else {
                    buildConf = dtoFactory.newDTO(PipelineNode.class).setJobCiId(parseProject.getJobCiId(false)).setName(project.getNameWithNamespace());
                }
                projectNames = projectNames + buildConf.getName() + ",";
                list.add(buildConf);
            } catch (Exception e) {
                log.warn("Failed to add some tags to the job list", e);
            }
        }
    } catch (Exception e) {
        log.warn("Failed to add some jobs to the job list", e);
    }
    log.info("getJobList results:" + projectNames);
    ciJobsList.setJobs(list.toArray(new PipelineNode[list.size()]));
    return ciJobsList;
}
Also used : CIJobsList(com.hp.octane.integrations.dto.general.CIJobsList) Project(org.gitlab4j.api.models.Project) ParsedPath(com.microfocus.octane.gitlab.helpers.ParsedPath) ProjectFilter(org.gitlab4j.api.models.ProjectFilter) ArrayList(java.util.ArrayList) PipelineNode(com.hp.octane.integrations.dto.pipelines.PipelineNode) MalformedURLException(java.net.MalformedURLException) GitLabApiException(org.gitlab4j.api.GitLabApiException)

Example 14 with Project

use of org.gitlab4j.api.models.Project in project octane-gitlab-service by MicroFocus.

the class MergeRequestHistoryHandler method startListening.

public void startListening() {
    taskExecutor.execute(() -> {
        WatchKey key;
        try {
            log.info("Listening for disk changes on " + watchPath + " ...");
            while ((key = watchService.take()) != null) {
                for (WatchEvent<?> event : key.pollEvents()) {
                    log.info("Disk change event occurred: " + event.context().toString() + " was deleted.");
                    String projectId = event.context().toString();
                    try {
                        Project project = gitLabApi.getProjectApi().getProject(projectId);
                        sendMergeRequestsToOctane(project);
                        Path pathToFile = Paths.get(watchPath.toString() + "/" + project.getId());
                        Files.createFile(pathToFile);
                    } catch (GitLabApiException | IOException e) {
                        log.error(e.getMessage(), e);
                    }
                }
                key.reset();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
}
Also used : Path(java.nio.file.Path) Project(org.gitlab4j.api.models.Project) WatchKey(java.nio.file.WatchKey) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Example 15 with Project

use of org.gitlab4j.api.models.Project in project catma by forTEXT.

the class GitSourceDocumentHandlerTest method tearDown.

@AfterEach
public void tearDown() throws Exception {
    if (directoriesToDeleteOnTearDown.size() > 0) {
        for (File dir : directoriesToDeleteOnTearDown) {
            // files have read-only attribute set on Windows, which we need to clear before the call to `deleteDirectory` will work
            for (Iterator<File> it = FileUtils.iterateFiles(dir, null, true); it.hasNext(); ) {
                File file = it.next();
                file.setWritable(true);
            }
            FileUtils.deleteDirectory(dir);
        }
        directoriesToDeleteOnTearDown.clear();
    }
    if (sourceDocumentReposToDeleteOnTearDown.size() > 0) {
        for (String sourceDocumentId : sourceDocumentReposToDeleteOnTearDown) {
            List<Project> projects = gitlabManagerPrivileged.getGitLabApi().getProjectApi().getProjects(sourceDocumentId);
            // this getProjects overload does a search
            for (Project project : projects) {
                gitlabManagerRestricted.deleteRepository(project.getId());
            }
            await().until(() -> gitlabManagerPrivileged.getGitLabApi().getProjectApi().getProjects().isEmpty());
        }
        sourceDocumentReposToDeleteOnTearDown.clear();
    }
    if (projectsToDeleteOnTearDown.size() > 0) {
        BackgroundService mockBackgroundService = mock(BackgroundService.class);
        EventBus mockEventBus = mock(EventBus.class);
        GitProjectManager gitProjectManager = new GitProjectManager(CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(), gitlabManagerRestricted, // noop deletion handler
        (projectId) -> {
        }, mockBackgroundService, mockEventBus);
        for (String projectId : projectsToDeleteOnTearDown) {
            gitProjectManager.delete(projectId);
        }
        projectsToDeleteOnTearDown.clear();
    }
    // delete the GitLab user that we created in setUp, including associated groups/repos
    // TODO: explicit deletion of associated repos (above) is now superfluous since we are doing a hard delete
    UserApi userApi = gitlabManagerPrivileged.getGitLabApi().getUserApi();
    userApi.deleteUser(gitlabManagerRestricted.getUser().getUserId(), true);
// GitLabServerManagerTest.awaitUserDeleted(userApi, gitlabManagerRestricted.getUser().getUserId());
}
Also used : Project(org.gitlab4j.api.models.Project) BackgroundService(de.catma.backgroundservice.BackgroundService) EventBus(com.google.common.eventbus.EventBus) UserApi(org.gitlab4j.api.UserApi) File(java.io.File) AfterEach(org.junit.jupiter.api.AfterEach)

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