Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Build association and sync dashboard - Testresult (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
nireeshT authored Mar 29, 2021
1 parent b0474c7 commit 6642b37
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>api</artifactId>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<version>3.4.10-SNAPSHOT</version>
<version>3.4.11-SNAPSHOT</version>
<description>Hygieia Rest API Layer</description>
<url>https://github.com/Hygieia/api</url>

Expand Down Expand Up @@ -59,7 +59,7 @@

<properties>
<!-- Dependencies -->
<com.capitalone.dashboard.core.version>3.14.11</com.capitalone.dashboard.core.version>
<com.capitalone.dashboard.core.version>3.14.12</com.capitalone.dashboard.core.version>
<spring-security.version>4.2.18.RELEASE</spring-security.version>
<tomcat.version>8.5.57</tomcat.version>
<commons-beanutils.version>1.9.4</commons-beanutils.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import com.capitalone.dashboard.model.quality.JunitXmlReport;
import com.capitalone.dashboard.model.quality.JunitXmlReportV2;
import com.capitalone.dashboard.repository.BuildRepository;
import com.capitalone.dashboard.repository.CollectorItemRepository;
import com.capitalone.dashboard.repository.CollectorRepository;
import com.capitalone.dashboard.repository.ComponentRepository;
import com.capitalone.dashboard.repository.TestResultRepository;
import com.capitalone.dashboard.request.CollectorRequest;
import com.capitalone.dashboard.request.PerfTestDataCreateRequest;
import com.capitalone.dashboard.request.TestDataCreateRequest;
import com.capitalone.dashboard.settings.ApiSettings;
import com.capitalone.dashboard.util.HygieiaUtils;
import com.capitalone.dashboard.util.TestResultConstants;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
Expand Down Expand Up @@ -50,6 +52,7 @@ public class TestResultServiceImpl implements TestResultService {
private final TestResultRepository testResultRepository;
private final ComponentRepository componentRepository;
private final CollectorRepository collectorRepository;
private final CollectorItemRepository collectorItemRepository;
private final BuildRepository buildRepository;
private final CollectorService collectorService;
private final CmdbService cmdbService;
Expand All @@ -62,13 +65,15 @@ public TestResultServiceImpl(TestResultRepository testResultRepository,
ComponentRepository componentRepository,
CollectorRepository collectorRepository,
BuildRepository buildRepository,
CollectorItemRepository collectorItemRepository,
CollectorService collectorService,
CmdbService cmdbService,
ApiSettings apiSettings) {
this.testResultRepository = testResultRepository;
this.componentRepository = componentRepository;
this.collectorRepository = collectorRepository;
this.buildRepository = buildRepository;
this.collectorItemRepository = collectorItemRepository;
this.collectorService = collectorService;
this.cmdbService = cmdbService;
this.apiSettings = apiSettings;
Expand Down Expand Up @@ -626,21 +631,26 @@ private TestResult createTestCucumber(CollectorItem collectorItem, CucumberJsonR
return result;
}

private void associateBuildToTestResult(String buildUrl, String clientReference, TestResult testResult){
if(Objects.nonNull(buildUrl)){
Build build = buildRepository.findByBuildUrl(buildUrl);
if(Objects.nonNull(build)){
build.setClientReference(clientReference);
testResult.setBuildId(build.getId());
buildRepository.save(build);
}else{
Build baseBuild = new Build();
baseBuild.setBuildUrl(buildUrl);
baseBuild.setBuildStatus(BuildStatus.InProgress);
baseBuild.setClientReference(clientReference);
baseBuild = buildRepository.save(baseBuild);
testResult.setBuildId(baseBuild.getId());
private void associateBuildToTestResult(String buildUrl, String clientReference, TestResult testResult) {
if (Objects.isNull(buildUrl)) return;
Build build = buildRepository.findByBuildUrl(buildUrl);
if (Objects.nonNull(build)) {
build.setClientReference(clientReference);
testResult.setBuildId(build.getId());
buildRepository.save(build);
} else {
Build baseBuild = new Build();
baseBuild.setBuildUrl(buildUrl);
String trailedBuildUrl = HygieiaUtils.normalizeJobUrl(buildUrl);
Collector collector = collectorRepository.findByName(apiSettings.getBuildCollectorName());
CollectorItem buildCollectorItem = collectorItemRepository.findByJobUrl(collector.getId(), trailedBuildUrl);
if(Objects.nonNull(buildCollectorItem)){
baseBuild.setCollectorItemId(buildCollectorItem.getId());
}
baseBuild.setBuildStatus(BuildStatus.InProgress);
baseBuild.setClientReference(clientReference);
baseBuild = buildRepository.save(baseBuild);
testResult.setBuildId(baseBuild.getId());
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/capitalone/dashboard/settings/ApiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class ApiSettings {
@Value("${gitToolName:Github}")
private String gitToolName;

@Value("${buildCollectorName:Hudson}")
private String buildCollectorName;

private WebHookSettings webHook;

private String capturePattern;
Expand Down Expand Up @@ -211,4 +214,12 @@ public void setDataSyncSettings(DataSyncSettings dataSyncSettings) {
public String getHygieia_ui_url() { return hygieia_ui_url; }

public void setHygieia_ui_url(String hygieia_ui_url) { this.hygieia_ui_url = hygieia_ui_url; }

public String getBuildCollectorName() {
return buildCollectorName;
}

public void setBuildCollectorName(String buildCollectorName) {
this.buildCollectorName = buildCollectorName;
}
}

0 comments on commit 6642b37

Please sign in to comment.