Search in sources :

Example 1 with Project

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);
}
Also used : Project(org.gitlab4j.api.models.Project) User(org.gitlab4j.api.models.User) GitLabApiException(org.gitlab4j.api.GitLabApiException) TestResultsCleanUpRunnable(com.microfocus.octane.gitlab.testresults.TestResultsCleanUpRunnable) PostConstruct(javax.annotation.PostConstruct)

Example 2 with Project

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);
    }
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) DependsOn(org.springframework.context.annotation.DependsOn) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WatchKey(java.nio.file.WatchKey) Variable(org.gitlab4j.api.models.Variable) StandardWatchEventKinds(java.nio.file.StandardWatchEventKinds) PullRequestHelper(com.microfocus.octane.gitlab.helpers.PullRequestHelper) Map(java.util.Map) MergeRequest(org.gitlab4j.api.models.MergeRequest) TaskExecutor(org.springframework.core.task.TaskExecutor) Path(java.nio.file.Path) Commit(org.gitlab4j.api.models.Commit) Files(java.nio.file.Files) VariablesHelper(com.microfocus.octane.gitlab.helpers.VariablesHelper) WatchEvent(java.nio.file.WatchEvent) IOException(java.io.IOException) ApplicationSettings(com.microfocus.octane.gitlab.app.ApplicationSettings) GitLabApiWrapper(com.microfocus.octane.gitlab.helpers.GitLabApiWrapper) Project(org.gitlab4j.api.models.Project) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) WatchService(java.nio.file.WatchService) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Diff(org.gitlab4j.api.models.Diff) Paths(java.nio.file.Paths) Optional(java.util.Optional) GitLabApiException(org.gitlab4j.api.GitLabApiException) LogManager(org.apache.logging.log4j.LogManager) GitLabApi(org.gitlab4j.api.GitLabApi) FileSystems(java.nio.file.FileSystems) Path(java.nio.file.Path) Project(org.gitlab4j.api.models.Project) Optional(java.util.Optional) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Project

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));
        }
    }
}
Also used : Project(org.gitlab4j.api.models.Project) GitLabMode(org.finos.legend.sdlc.server.gitlab.mode.GitLabMode) Test(org.junit.Test)

Example 4 with 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;
}
Also used : NotesApi(org.gitlab4j.api.NotesApi) JsonObject(com.google.gson.JsonObject) Reply(de.catma.document.comment.Reply) AccessLevel(org.gitlab4j.api.models.AccessLevel) ProjectFilter(org.gitlab4j.api.models.ProjectFilter) StringUtils(org.apache.commons.lang3.StringUtils) Author(org.gitlab4j.api.models.Author) IssuesApi(org.gitlab4j.api.IssuesApi) ChangeUserAttributeEvent(de.catma.ui.events.ChangeUserAttributeEvent) Map(java.util.Map) Group(org.gitlab4j.api.models.Group) IssueState(org.gitlab4j.api.Constants.IssueState) GroupApi(org.gitlab4j.api.GroupApi) Visibility(org.gitlab4j.api.models.Visibility) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) IGitUserInformation(de.catma.repository.git.interfaces.IGitUserInformation) GitMember(de.catma.repository.git.GitMember) Pager(org.gitlab4j.api.Pager) GitlabUtils(de.catma.repository.git.GitlabUtils) Set(java.util.Set) Logger(java.util.logging.Logger) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) Collectors(java.util.stream.Collectors) ProjectReference(de.catma.project.ProjectReference) Objects(java.util.Objects) List(java.util.List) ProjectApi(org.gitlab4j.api.ProjectApi) Optional(java.util.Optional) GitLabApiException(org.gitlab4j.api.GitLabApiException) Status(org.gitlab4j.api.models.ImportStatus.Status) CacheBuilder(com.google.common.cache.CacheBuilder) GitLabApi(org.gitlab4j.api.GitLabApi) RBACPermission(de.catma.rbac.RBACPermission) Permissions(org.gitlab4j.api.models.Permissions) GroupFilter(org.gitlab4j.api.models.GroupFilter) Namespace(org.gitlab4j.api.models.Namespace) HashMap(java.util.HashMap) RBACRole(de.catma.rbac.RBACRole) JsonParser(com.google.gson.JsonParser) User(de.catma.user.User) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) EventBus(com.google.common.eventbus.EventBus) IRemoteGitManagerRestricted(de.catma.repository.git.interfaces.IRemoteGitManagerRestricted) Comment(de.catma.document.comment.Comment) ForkStatus(de.catma.project.ForkStatus) GitProjectManager(de.catma.repository.git.GitProjectManager) Note(org.gitlab4j.api.models.Note) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) CreateRepositoryResponse(de.catma.repository.git.CreateRepositoryResponse) Issue(org.gitlab4j.api.models.Issue) IOException(java.io.IOException) Project(org.gitlab4j.api.models.Project) Maps(com.google.common.collect.Maps) IssueFilter(org.gitlab4j.api.models.IssueFilter) TimeUnit(java.util.concurrent.TimeUnit) Member(org.gitlab4j.api.models.Member) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) BackgroundService(de.catma.backgroundservice.BackgroundService) GitUser(de.catma.repository.git.GitUser) Project(org.gitlab4j.api.models.Project) ProjectFilter(org.gitlab4j.api.models.ProjectFilter) ProjectApi(org.gitlab4j.api.ProjectApi) Permissions(org.gitlab4j.api.models.Permissions) AccessLevel(org.gitlab4j.api.models.AccessLevel)

Example 5 with Project

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");
    }
}
Also used : NotesApi(org.gitlab4j.api.NotesApi) JsonObject(com.google.gson.JsonObject) Reply(de.catma.document.comment.Reply) AccessLevel(org.gitlab4j.api.models.AccessLevel) ProjectFilter(org.gitlab4j.api.models.ProjectFilter) StringUtils(org.apache.commons.lang3.StringUtils) Author(org.gitlab4j.api.models.Author) IssuesApi(org.gitlab4j.api.IssuesApi) ChangeUserAttributeEvent(de.catma.ui.events.ChangeUserAttributeEvent) Map(java.util.Map) Group(org.gitlab4j.api.models.Group) IssueState(org.gitlab4j.api.Constants.IssueState) GroupApi(org.gitlab4j.api.GroupApi) Visibility(org.gitlab4j.api.models.Visibility) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) IGitUserInformation(de.catma.repository.git.interfaces.IGitUserInformation) GitMember(de.catma.repository.git.GitMember) Pager(org.gitlab4j.api.Pager) GitlabUtils(de.catma.repository.git.GitlabUtils) Set(java.util.Set) Logger(java.util.logging.Logger) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) Collectors(java.util.stream.Collectors) ProjectReference(de.catma.project.ProjectReference) Objects(java.util.Objects) List(java.util.List) ProjectApi(org.gitlab4j.api.ProjectApi) Optional(java.util.Optional) GitLabApiException(org.gitlab4j.api.GitLabApiException) Status(org.gitlab4j.api.models.ImportStatus.Status) CacheBuilder(com.google.common.cache.CacheBuilder) GitLabApi(org.gitlab4j.api.GitLabApi) RBACPermission(de.catma.rbac.RBACPermission) Permissions(org.gitlab4j.api.models.Permissions) GroupFilter(org.gitlab4j.api.models.GroupFilter) Namespace(org.gitlab4j.api.models.Namespace) HashMap(java.util.HashMap) RBACRole(de.catma.rbac.RBACRole) JsonParser(com.google.gson.JsonParser) User(de.catma.user.User) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) EventBus(com.google.common.eventbus.EventBus) IRemoteGitManagerRestricted(de.catma.repository.git.interfaces.IRemoteGitManagerRestricted) Comment(de.catma.document.comment.Comment) ForkStatus(de.catma.project.ForkStatus) GitProjectManager(de.catma.repository.git.GitProjectManager) Note(org.gitlab4j.api.models.Note) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) CreateRepositoryResponse(de.catma.repository.git.CreateRepositoryResponse) Issue(org.gitlab4j.api.models.Issue) IOException(java.io.IOException) Project(org.gitlab4j.api.models.Project) Maps(com.google.common.collect.Maps) IssueFilter(org.gitlab4j.api.models.IssueFilter) TimeUnit(java.util.concurrent.TimeUnit) Member(org.gitlab4j.api.models.Member) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) BackgroundService(de.catma.backgroundservice.BackgroundService) GitUser(de.catma.repository.git.GitUser) HashMap(java.util.HashMap) ProjectApi(org.gitlab4j.api.ProjectApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Project(org.gitlab4j.api.models.Project) GitMember(de.catma.repository.git.GitMember) GitMember(de.catma.repository.git.GitMember) Member(org.gitlab4j.api.models.Member)

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