Search in sources :

Example 1 with TestResultsCleanUpRunnable

use of com.microfocus.octane.gitlab.testresults.TestResultsCleanUpRunnable 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)

Aggregations

TestResultsCleanUpRunnable (com.microfocus.octane.gitlab.testresults.TestResultsCleanUpRunnable)1 PostConstruct (javax.annotation.PostConstruct)1 GitLabApiException (org.gitlab4j.api.GitLabApiException)1 Project (org.gitlab4j.api.models.Project)1 User (org.gitlab4j.api.models.User)1