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");
}
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);
}
}
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;
}
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();
}
});
}
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());
}
Aggregations