Question on coverage % returned from api/measures/component GET

Issue with detail:

  • GitHub

  • Circle CI

  • Command - ./gradlew jacocoTestReport sonarqube -Dsonar.qualitygate.wait=true

  • Java

  • In a pipeline, we use a custom orb to run some commands to fetch data from Sonar scans - when we do a request to get the scores from a PR, like this:

"https://sonarcloud.io/api/measures/component?component=example_service-madeup2&metricKeys=coverage&pullRequest=237"

it’s returning this response:

{"component":{"id":"XXXXXXXX","key":"example_service-madeup2","name":"XXXX","qualifier":"TRK","measures":[{"metric":"coverage","value":"94.4","bestValue":false}],"pullRequest":"237"}}

That value in there, 94.4 looks to not be the actual value calculated on the Sonar results run in the UI (can provide links etc. in a private support request but not here) - you can see there the actual coverage is 100%, which shouldn’t result in any degradation in coverage, however if you look in the UI under the score of 100% coverage, we can see an estimated value after merge (screenshot attached) which makes little sense as the coverage on the PR is 100%

How come the API call returns the estimated value rather than the actual value?

If you want to return the value on only new code (the code changed in the PR), you should use new_coverage instead of coverage.