【问题标题】:Sonarqube REST API : What is the structure of "metrics" in "GET api/measures/component" WSSonarqube REST API:“GET api/measures/component”WS 中“metrics”的结构是什么
【发布时间】:2021-09-13 17:08:51
【问题描述】:

在 web api 文档的响应示例中,我可以看到度量标准“ncloc”在 JSON web 响应中应该是这样的:

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

但事实并非如此,在我的回复中,该指标没有“句号”:

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

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

所以这是我的问题: 我如何知道指标的预期结构?什么是“时期”将有一个时期列表而不仅仅是一个对应于“新代码”的度量标准?

【问题讨论】:

    标签: rest web-services sonarqube


    【解决方案1】:

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

    编辑:

    以下是8.9的文档:

    获取 api/measures/组件

    自 5.4 起

    返回具有指定度量的组件。 需要以下权限:“浏览”指定组件的项目。

    参数

    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

    响应示例

    {
     "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"
     }
    }
    

    更新日志

    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.

    【讨论】:

    • 这很有趣,我在 7.9,你能在你的答案中显示 8.9 的响应示例吗? (这些文档在互联网上不存在,您需要安装实例才能查看)。
    • 好的,很好。根据“响应字段周期已弃用。请改用周期。”,看起来他们意识到从来没有多个周期。
    猜你喜欢
    • 2019-06-12
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    相关资源
    最近更新 更多