Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send total coverage back to GitLab instead of new coverage #225

Merged
merged 1 commit into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ public Optional<String> getScannerProperty(String propertyName) {
public String createAnalysisSummary(FormatterFactory formatterFactory) {

BigDecimal newCoverage = getNewCoverage().orElse(null);


double coverage = findMeasure(CoreMetrics.COVERAGE_KEY).map(Measure::getDoubleValue).orElse(0D);
BigDecimal coverage = getCoverage().orElse(null);

BigDecimal newDuplications = findQualityGateCondition(CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY)
.filter(condition -> condition.getStatus() != EvaluationStatus.NO_VALUE)
Expand Down Expand Up @@ -354,6 +352,10 @@ public Optional<BigDecimal> getNewCoverage(){
.map(BigDecimal::new);
}

public Optional<BigDecimal> getCoverage(){
return findMeasure(CoreMetrics.COVERAGE_KEY).map(Measure::getDoubleValue).map(BigDecimal::new);
}

public static class BranchDetails {

private final String branchName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public DecorationResult decorateQualityGateStatus(AnalysisDetails analysis, AlmS
List<NameValuePair> summaryContentParams = Collections
.singletonList(new BasicNameValuePair("body", summaryComment));

String coverageValue = analysis.getNewCoverage().orElse(BigDecimal.ZERO).toString();
BigDecimal coverageValue = analysis.getCoverage().orElse(null);

postStatus(new StringBuilder(statusUrl), headers, analysis, coverageValue);

Expand Down Expand Up @@ -315,7 +315,7 @@ private void postCommitComment(String commitCommentUrl, Map<String, String> head
}

private void postStatus(StringBuilder statusPostUrl, Map<String, String> headers, AnalysisDetails analysis,
String coverage) throws IOException {
BigDecimal coverage) throws IOException {
//See https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit
statusPostUrl.append("?name=SonarQube");
String status = (analysis.getQualityGateStatus() == QualityGate.Status.OK ? "success" : "failed");
Expand All @@ -326,7 +326,9 @@ private void postStatus(StringBuilder statusPostUrl, Map<String, String> headers
.encode(analysis.getBranchName(),
StandardCharsets.UTF_8.name())), StandardCharsets.UTF_8.name()));
statusPostUrl.append("&description=").append(URLEncoder.encode("SonarQube Status", StandardCharsets.UTF_8.name()));
statusPostUrl.append("&coverage=").append(coverage);
if (coverage != null) {
statusPostUrl.append("&coverage=").append(coverage.toString());
}
analysis.getScannerProperty(PULLREQUEST_GITLAB_PIPELINE_ID).ifPresent(pipelineId -> statusPostUrl.append("&pipeline_id=").append(pipelineId));

HttpPost httpPost = new HttpPost(statusPostUrl.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void decorateQualityGateStatus() {
when(analysisDetails.getAnalysisProjectKey()).thenReturn(projectKey);
when(analysisDetails.getBranchName()).thenReturn(branchName);
when(analysisDetails.getCommitSha()).thenReturn(commitSHA);
when(analysisDetails.getNewCoverage()).thenReturn(Optional.of(BigDecimal.TEN));
when(analysisDetails.getCoverage()).thenReturn(Optional.of(BigDecimal.TEN));
PostAnalysisIssueVisitor issueVisitor = mock(PostAnalysisIssueVisitor.class);
PostAnalysisIssueVisitor.ComponentIssue componentIssue = mock(PostAnalysisIssueVisitor.ComponentIssue.class);
DefaultIssue defaultIssue = mock(DefaultIssue.class);
Expand Down