Skip to content

Commit

Permalink
Added recursive path parse + Fixed cleanupOnly behaviour (#106)
Browse files Browse the repository at this point in the history
* Added recursive path parse + Fixed cleanupOnly behaviour

* Removed useless import

* Added optional Job

---------

Co-authored-by: Madalin Tiutiu <Madalin.Tiutiu@microfocus.com>
  • Loading branch information
TiutiuMadalin and Madalin Tiutiu committed Dec 18, 2023
1 parent 53423a1 commit 4119e9c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ private void init() throws MalformedURLException {
log.warn("Failed to create GitLab web hooks", e);
throw new RuntimeException(e);
}

//start test cleanUp thread
testCleanupExecutor =
Executors.newSingleThreadScheduledExecutor();
testCleanupScheduledFuture = testCleanupExecutor.scheduleAtFixedRate(
new TestResultsCleanUpRunnable(applicationSettings.getConfig().getTestResultsOutputFolderPath()), TestResultsCleanUpRunnable.INTERVAL, TestResultsCleanUpRunnable.INTERVAL, TimeUnit.MINUTES);

if(!cleanupOnly) {
//start test cleanUp thread
testCleanupExecutor = Executors.newSingleThreadScheduledExecutor();
testCleanupScheduledFuture = testCleanupExecutor.scheduleAtFixedRate(
new TestResultsCleanUpRunnable(applicationSettings.getConfig().getTestResultsOutputFolderPath()),
TestResultsCleanUpRunnable.INTERVAL, TestResultsCleanUpRunnable.INTERVAL, TimeUnit.MINUTES);
}
}

private void initWebHookListenerURL() throws MalformedURLException {
Expand All @@ -147,16 +147,16 @@ private void initWebHookListenerURL() throws MalformedURLException {
@PreDestroy
private void stop() {
try {
if(!cleanupOnly) {
stopExecutors();

stopExecutors();
log.info("Destroying GitLab webhooks ...");

log.info("Destroying GitLab webhooks ...");
ProjectFilter filter = new ProjectFilter().withMembership(true).withMinAccessLevel(AccessLevel.MAINTAINER);

ProjectFilter filter = new ProjectFilter().withMembership(true)
.withMinAccessLevel(AccessLevel.MAINTAINER);

List<Project> projects = gitLabApi.getProjectApi().getProjects(filter);
HooksHelper.deleteWebHooks(projects,webhookURL,gitLabApi);
List<Project> projects = gitLabApi.getProjectApi().getProjects(filter);
HooksHelper.deleteWebHooks(projects, webhookURL, gitLabApi);
}

} catch (Exception e) {
log.warn("Failed to destroy GitLab webhooks", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,28 @@ public CIBranchesList getBranchesList(String jobCiId, String filterBranchName) {
}


private Optional<Job> extractGitLabJob (ParsedPath project, String buildNumber){
try {
if (project.getPathWithNameSpace().isEmpty())
throw new RuntimeException("Can not find gitlab project path");
return Optional.of(gitLabApi.getJobApi().getJob(project.getPathWithNameSpace(), Long.parseLong(buildNumber)));
} catch (GitLabApiException e){
return Optional.empty();
}
}


@Override
public InputStream getTestsResult(String jobFullName, String buildNumber) {
TestsResult result = dtoFactory.newDTO(TestsResult.class);
try {
ParsedPath project = new ParsedPath(ParsedPath.cutLastPartOfPath(jobFullName), gitLabApi, PathType.PROJECT);
Job job = gitLabApi.getJobApi().getJob(project.getPathWithNameSpace(), Long.parseLong(buildNumber));
Optional<Job> optionalJob = extractGitLabJob(project, buildNumber);
while (optionalJob.isEmpty()){
project = new ParsedPath(ParsedPath.cutLastPartOfPath(project.getPathWithNameSpace()), gitLabApi, PathType.PROJECT);
optionalJob = extractGitLabJob(project, buildNumber);
}
Job job = optionalJob.get();

//report gherkin test results

Expand Down

0 comments on commit 4119e9c

Please sign in to comment.