【问题标题】:Get full JSON response from Sonarqube Web API从 Sonarqube Web API 获取完整的 JSON 响应
【发布时间】:2018-11-03 23:36:30
【问题描述】:

我正在使用 Sonarqube Web API 来检测 spoon 中的错误。但是我没有得到大约 189 个错误的完整列表,但即使我使用 types=BUG 参数也只有大约 100 个。我使用的 GET 请求是 https://sonarqube.ow2.org/api/issues/search?componentKeys=fr.inria.gforge.spoon:spoon-core&types=BUG 。有什么方法可以获得完整的 JSON 响应?

【问题讨论】:

    标签: sonarqube


    【解决方案1】:

    您只会得到 100 个项目,因为 100 是 Web api 分页的默认页面大小。 在您使用时的示例中:

    https://sonarqube.ow2.org/api/issues/search?componentKeys=fr.inria.gforge.spoon:spoon-core&types=BUG&ps=200
    

    你会得到所有 189 个错误。 pagesize 的最大值为 500。
    如果您想知道问题的总数,您需要查看回复:

    {
      "paging": {
        "pageIndex": 1,
        "pageSize": 100,
        "total": 189 <<---------------------------
      },
      "issues": [
        {
    ...
    

    一个 groovy sn-p 使用 total 来解决所有循环问题:

    import groovy.json.*
    
    def sonarRest(url,method) {
      jsonSlurper = new JsonSlurper()
      raw = '...:'
      bauth = 'Basic ' + javax.xml.bind.DatatypeConverter.printBase64Binary(raw.getBytes())
      conn = new URL(url).openConnection() as HttpURLConnection
      conn.setRequestMethod(method)
      conn.setRequestProperty("Authorization", bauth)
      conn.connect()
      httpstatus = conn.responseCode
      object = jsonSlurper.parse(conn.content)
    }
    
    issues = sonarRest('https://sonarhost/api/issues/search?severities=INFO&ps=1', 'GET')
    total = (issues.total.toFloat()/100).round()
    
    counter = 1
    
    while(counter <= total)
    {
    issues = sonarRest("https://sonarhost/api/issues/search?severities=INFO&ps=100&p=$counter", 'GET')
    println issues
    counter++
    }
    

    【讨论】:

    【解决方案2】:

    对不起,我什至不需要它。我可以向参数添加规则,因为我一次只使用一个规则。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-28
      • 1970-01-01
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      • 2017-12-20
      • 1970-01-01
      • 2019-05-12
      相关资源
      最近更新 更多