您只会得到 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++
}