【问题标题】:Check the code coverage for a project on sonar with rest api使用 rest api 检查声纳项目的代码覆盖率
【发布时间】:2019-08-07 00:41:04
【问题描述】:

声纳版本:5.3

我正在打这个电话

https://mysonar/api/resources/index?metrics=coverage&key=test-project

但是,我没有从这个调用中得到测试项目的覆盖率。 但我得到了其余的项目和他们的报道。 当我这样做时

https://sonaraws.kdc.capitalone.com/api/resources/index

我可以在 api 响应中看到我的测试项目。

我如何深入到特定项目,而不是从对 Sonar 的其余调用中检查其他项目。

【问题讨论】:

    标签: sonarqube sonarqube-scan


    【解决方案1】:

    我正在使用下面的 api 来获取覆盖率。 Sonarqube 版本 - 6.7.5

    使用下面列出的第一个 api 获取项目的 componentId。

    https://sonarurl/api/components/show?key=ProjectKey
    
    https://sonarurl/api/measures/component?componentId=Ahvhjvds87373&metricKeys=coverage
    

    回应

    {
        "component": {
            "id": "Ahvhjvds87373",
            "key": "ProjectKey",
            "name": "ProjectName",
            "qualifier": "TRK",
            "measures": [{
                "metric": "coverage",
                "value": "79.3",
                "periods": [{
                    "index": 1,
                    "value": "0.0"
                }]
            }]
        }
    }
    

    【讨论】:

      【解决方案2】:

      api/resources 不支持key 参数。您必须使用qualifiersresource 参数指定项目ID。

      这应该适合你:

      https://mysonar/api/resources/index?metrics=coverage&qualifiers=TRK&resource=test-project
      

      qualifiers 参数的可用值:

      • 大众:查看
      • 上海大众:子视图
      • TRK:项目
      • BRC:模块
      • UTS:单元测试
      • DIR:目录
      • FIL:文件
      • DEV:开发人员

      【讨论】:

        猜你喜欢
        • 2014-10-03
        • 2012-09-04
        • 2013-11-21
        • 2014-11-12
        • 2016-10-19
        • 2012-09-30
        • 2016-06-23
        • 2018-08-22
        • 1970-01-01
        相关资源
        最近更新 更多