use of org.gitlab4j.api.models.Project in project octane-gitlab-service by MicroFocus.
the class GitlabServices method init.
@PostConstruct
private void init() throws MalformedURLException {
// Adding webHooks
initWebHookListenerURL();
gitLabApi = gitLabApiWrapper.getGitLabApi();
try {
List<Project> projects = isCurrentUserAdmin() ? gitLabApi.getProjectApi().getProjects() : gitLabApi.getProjectApi().getMemberProjects();
User currentUser = gitLabApi.getUserApi().getCurrentUser();
if (cleanupOnly) {
log.info("start with cleanup process");
for (Project project : projects) {
if (gitLabApiWrapper.isUserHasPermissionForProject(project, currentUser)) {
deleteWebHooks(project.getId());
}
}
} else {
for (Project project : projects) {
if (gitLabApiWrapper.isUserHasPermissionForProject(project, currentUser)) {
addWebHookToProject(project.getId(), true);
}
}
}
} catch (GitLabApiException e) {
log.warn("Failed to create GitLab web hooks", e);
throw new RuntimeException(e);
}
// start cleanUp thread
executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleAtFixedRate(new TestResultsCleanUpRunnable(applicationSettings.getConfig().getTestResultsOutputFolderPath()), TestResultsCleanUpRunnable.INTERVAL, TestResultsCleanUpRunnable.INTERVAL, TimeUnit.MINUTES);
}
use of org.gitlab4j.api.models.Project in project octane-gitlab-service by MicroFocus.
the class MergeRequestHistoryHandler method executeFirstScan.
public void executeFirstScan() {
try {
List<Project> gitLabProjects = gitLabApi.getProjectApi().getProjects().stream().filter(project -> {
Map<String, String> projectGroupVariables = VariablesHelper.getProjectGroupVariables(gitLabApi, project);
Optional<Variable> shouldPublishToOctane = VariablesHelper.getProjectVariable(gitLabApi, project.getId(), applicationSettings.getConfig().getPublishMergeRequestsVariableName());
return (shouldPublishToOctane.isPresent() && Boolean.parseBoolean(shouldPublishToOctane.get().getValue())) || (projectGroupVariables.containsKey(applicationSettings.getConfig().getPublishMergeRequestsVariableName()) && Boolean.parseBoolean(projectGroupVariables.get(applicationSettings.getConfig().getPublishMergeRequestsVariableName())));
}).collect(Collectors.toList());
gitLabProjects.forEach(project -> {
try {
Path pathToFile = Paths.get(watchPath.toString() + "/" + project.getId());
if (!Files.exists(pathToFile)) {
sendMergeRequestsToOctane(project);
Files.createFile(pathToFile);
}
} catch (GitLabApiException | IOException e) {
log.warn(e.getMessage(), e);
}
});
} catch (GitLabApiException e) {
log.error(e.getMessage(), e);
}
}
use of org.gitlab4j.api.models.Project in project legend-sdlc by finos.
the class TestGitLabProjectId method testGetProjectIdString.
@Test
public void testGetProjectIdString() {
for (GitLabMode mode : GitLabMode.values()) {
for (int i = 0; i < 1024; i++) {
Project project = new Project().withId(i);
Assert.assertEquals(mode.name() + "-" + i, GitLabProjectId.getProjectIdString(mode, project));
}
}
}
use of org.gitlab4j.api.models.Project in project catma by forTEXT.
the class GitlabManagerRestricted method getResourcePermissions.
private Map<String, AccessLevel> getResourcePermissions(Integer groupId) throws GitLabApiException {
Map<String, AccessLevel> resultMap = Maps.newHashMap();
ProjectApi projectApi = new ProjectApi(restrictedGitLabApi);
logger.info("Loading project permissions");
List<Project> resourceAndContainerProjects = projectApi.getProjects(new ProjectFilter().withMembership(true));
logger.info(String.format("Filtering %1$d resources on group #%2$d", resourceAndContainerProjects.size(), groupId));
Set<Project> filteredOnGroupProjects = resourceAndContainerProjects.stream().filter(p -> p.getNamespace().getId().equals(groupId)).collect(Collectors.toSet());
logger.info(String.format("Updating accesslevel registry for %1$d resources", filteredOnGroupProjects.size()));
for (Project p : filteredOnGroupProjects) {
Permissions permission = p.getPermissions();
if (permission.getGroupAccess() != null) {
resultMap.put(p.getName(), permission.getGroupAccess().getAccessLevel());
}
if (permission.getProjectAccess() != null && (!resultMap.containsKey(p.getName()) || resultMap.get(p.getName()).value.intValue() < permission.getProjectAccess().getAccessLevel().value.intValue())) {
resultMap.put(p.getName(), permission.getProjectAccess().getAccessLevel());
}
}
return resultMap;
}
use of org.gitlab4j.api.models.Project in project catma by forTEXT.
the class GitlabManagerRestricted method getResourceMembers.
@Override
public Set<de.catma.user.Member> getResourceMembers(String projectId, String resourceId) throws IOException {
try {
Project project = restrictedGitLabApi.getProjectApi().getProject(projectId, resourceId);
if (project != null) {
List<GitMember> allMembers = new ProjectApi(restrictedGitLabApi).getAllMembers(project.getId()).stream().map(member -> new GitMember(member)).collect(Collectors.toList());
Map<Integer, de.catma.user.Member> mergedList = new HashMap<>();
for (de.catma.user.Member m : allMembers) {
if (!mergedList.containsKey(m.getUserId()) || mergedList.get(m.getUserId()).getRole().getAccessLevel() < m.getRole().getAccessLevel()) {
mergedList.put(m.getUserId(), m);
}
}
return mergedList.values().stream().collect(Collectors.toSet());
} else {
throw new IOException("resource unknown");
}
} catch (GitLabApiException e) {
throw new IOException("resource unknown");
}
}
Aggregations