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

Gitlab PR decoration throws exception when no new_coverage condition is provided #85

Closed
kortov opened this issue Feb 6, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@kortov
Copy link

kortov commented Feb 6, 2020

Describe the bug
When in Sonar conditions there is no new_coverage condition (and i doubt that this condition is necessary) the plugin throws Exception. IllegalStateException("Could not find New Coverage Condition in analysis"). I guess it's kinda related to #62 but the reason of the issue lies here

QualityGate.Condition newCoverageCondition = analysis.findQualityGateCondition(CoreMetrics.NEW_COVERAGE_KEY)
.orElseThrow(() -> new IllegalStateException("Could not find New Coverage Condition in analysis"));
String coverageValue = newCoverageCondition.getStatus().equals(QualityGate.EvaluationStatus.NO_VALUE) ? "0" : newCoverageCondition.getValue();

The easiest solution would be

String coverageValue = analysis.findQualityGateCondition(CoreMetrics.NEW_COVERAGE_KEY)
                            .filter(condition -> condition.getStatus() != QualityGate.EvaluationStatus.NO_VALUE)
                            .map(QualityGate.Condition::getValue)
                            .orElse("0");

it's kinda duplicates the code from here

BigDecimal newCoverage =
findQualityGateCondition(CoreMetrics.NEW_COVERAGE_KEY)
.filter(condition -> condition.getStatus() != EvaluationStatus.NO_VALUE)
.map(QualityGate.Condition::getValue)
.map(BigDecimal::new)
.orElse(null);

So may be we can put some duplicated lines into separate method from AnalysisDetails.java. I unfortunately have no idea how to implement fix nicely

Expected behavior
The plugin should not throw an exception. May be only log some info.

Screenshots
If applicable, add screenshots to help explain your problem.

Software Versions

  • SonarQube Version: Version 7.9.2
  • Plugin Version: custom build from master at commit 1e28de6]
@kortov kortov added the bug Something isn't working label Feb 6, 2020
tisoft added a commit to tisoft/sonarqube-community-branch-plugin that referenced this issue Feb 12, 2020
@mc1arke
Copy link
Owner

mc1arke commented Feb 20, 2020

Fixed in #87

@mc1arke mc1arke closed this as completed Feb 20, 2020
bmaehr pushed a commit to bmaehr/sonarqube-community-branch-plugin that referenced this issue Feb 22, 2020
Grintek pushed a commit to Grintek/sonarqube-community-branch-plugin that referenced this issue Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants