New code coverage metrics not returning values from SonarQube 5.3 API

怎甘沉沦 提交于 2019-12-08 13:14:46

问题


I need to fetch unit test coverage data for new code changes via the api. The metrics. I can see the data in SonarQubeDashboard but the api is not returning any values for the metrics like:

  1. new_coverage
  2. new_line_coverage (etc)

I am invoking the api :

https:///api/resources?format=json&metrics=ncloc,line_coverage,new_line_coverage

Even the Public Nemo Instance does not return these metric values:

https://nemo.sonarqube.org/api/resources?format=json&metrics=ncloc,line_coverage,new_line_coverage,new_coverage

The above API is returning only ncloc and line_coverage for each and every project.

Please dont tell me to check if these metrics are not available in the version. They are, if you invoke the API:

https://nemo.sonarqube.org/api/metrics/search


回答1:


The modern way (api/measures/component)

SonarQube's api/resources Web API is deprecated, you should use api/measures/component instead (since 5.4).

Using this project as an example:

https://nemo.sonarqube.org/api/measures/component?componentKey=org.sonarsource.php%3Aphp&metricKeys=ncloc,line_coverage,new_line_coverage,new_coverage&additionalFields=metrics,periods

The old way (api/resources)

If you're really stuck with api/resources (e.g. old SonarQube version), then keep in mind that for new metrics there is a notion of time delta (new since when ?), so you have to add includetrends=true to your request. Let's do that with your example:

https://nemo.sonarqube.org/api/resources?format=json&metrics=ncloc,line_coverage,new_line_coverage,new_coverage&includetrends=true

This gives you new_coverage and new_line_coverage (for the projects which do have coverage and SCM information available).



来源:https://stackoverflow.com/questions/36250667/new-code-coverage-metrics-not-returning-values-from-sonarqube-5-3-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!