Reputation: 9121
In the response example from the web api documentation, I can see metric "ncloc" should be like this in the JSON web response :
"measures": [
{
"metric": "ncloc",
"value": "114",
"periods": [
{
"index": 1,
"value": "3"
}
]
},
But it's not, there is no "periods" for this metric in my response :
"measures":[
{
"metric": "ncloc",
"value": "2943"
},
There are "periods" for some other metrics though, and in this case, there is no metric value, only a value for each period (and there are never multiple periods, only one corresponding to the "new code" period).
So here are my questions about this : How can I know which structure to expect for a metric ? what would be the metric where "periods" would have a list of periods and not just one corresponding to "new code" ?
Upvotes: 0
Views: 3283
Reputation: 4261
I don't think there are multiple periods. API documentation for my version (8.9) only states period
, which probably stands for Leak Period as the New Code used to be called. I assume that general value is for overall value and period value is for the new code. Some measures may not make sense or be counted for overall or new code, so I would not make assumptions on whether there will be a metric value for the period or general.
Edit:
The following is the 8.9 documentation:
GET api/measures/component
SINCE 5.4
Return component with specified measures. Requires the following permission: 'Browse' on the project of specified component.
Parameters
Parameter Required? Since Description Example value additionalFields optional Comma-separated list of additional fields that can be returned in the response. Possible values: metrics, period, periods Example value: period,metrics branch optional 6.6 Branch key. Not available in the community edition. Example value: feature/my_branch component required Component key Example value: my_project metricKeys required Comma-separated list of metric keys Example value: ncloc,complexity,violations pullRequest optional 7.1 Pull request id. Not available in the community edition. Example value: 5461 Response Example
{ "component": { "key": "MY_PROJECT:ElementImpl.java", "name": "ElementImpl.java", "qualifier": "FIL", "language": "java", "path": "src/main/java/com/sonarsource/markdown/impl/ElementImpl.java", "measures": [ { "metric": "complexity", "value": "12", "period": { "value": "2", "bestValue": false } }, { "metric": "new_violations", "period": { "value": "25", "bestValue": false } }, { "metric": "ncloc", "value": "114", "period": { "value": "3", "bestValue": false } } ] }, "metrics": [ { "key": "complexity", "name": "Complexity", "description": "Cyclomatic complexity", "domain": "Complexity", "type": "INT", "higherValuesAreBetter": false, "qualitative": false, "hidden": false, "custom": false }, { "key": "ncloc", "name": "Lines of code", "description": "Non Commenting Lines of Code", "domain": "Size", "type": "INT", "higherValuesAreBetter": false, "qualitative": false, "hidden": false, "custom": false }, { "key": "new_violations", "name": "New issues", "description": "New Issues", "domain": "Issues", "type": "INT", "higherValuesAreBetter": false, "qualitative": true, "hidden": false, "custom": false } ], "period": { "mode": "previous_version", "date": "2016-01-11T10:49:50+0100", "parameter": "1.0-SNAPSHOT" } }
Changelog
Version Change 8.8 deprecated response field 'id' has been removed. 8.8 deprecated response field 'refId' has been removed. 8.1 the response field periods under measures field is deprecated. Use period instead. 8.1 the response field periods is deprecated. Use period instead. 7.6 The use of module keys in parameter 'component' is deprecated 6.6 the response field 'id' is deprecated. Use 'key' instead. 6.6 the response field 'refId' is deprecated. Use 'refKey' instead.
Upvotes: 1