Sonarqube REST API : "GET api/measures/component" WS 中 "metrics" 的结构是什么

Sonarqube REST API : What is the structure of "metrics" in "GET api/measures/component" WS

在网络 api 文档的响应示例中,我可以在 JSON 网络响应中看到指标“ncloc”应该是这样的:

  "measures": [
  {
    "metric": "ncloc",
    "value": "114",
    "periods": [
      {
        "index": 1,
        "value": "3"
      }
    ]
  },

但事实并非如此,我的回复中没有针对此指标的“句点”:

"measures":[
{
  "metric": "ncloc",
  "value": "2943"
},

虽然其他一些指标有“周期”,但在这种情况下,没有指标值,每个周期只有一个值(而且永远不会有多个周期,只有一个对应于“新代码”期)。

所以这是我对此的问题: 我怎么知道指标的结构是什么?如果“期间”有一个期间列表,而不仅仅是一个对应于“新代码”的期间,那么度量标准是什么?

我不认为有多个时期。 API 我的版本 (8.9) 的文档仅说明 period,这可能代表 Leak Period 作为 New Code曾经被称为。我假设一般价值是针对整体价值的,而期间价值是针对新代码的。某些度量可能没有意义或不会被计入整体代码或新代码,因此我不会假设该期间或一般是否会有度量值。

编辑:

以下为8.9文档:

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.