Unable to get full pull branch analysys report using webapi

Team,

I am using python to get pullrequest analysis report that shows coverage details on a branch but response is just a list of all pull request and not the one am looking for. my goal is to get pull branch analysis report locally so that i can get coverage percentage and use it somewhere else.

url = 'http://sonar.swteam.com:9000/api/project_pull_requests/list?project=team-pba&branch=refs/changes/22/115022/8'
myToken = 'xxxxxx'
session = requests.Session()
session.auth = myToken, ''
call = getattr(session, 'get')
res = call(url)
print(res.status_code)
binary = res.content
output1 = json.loads(binary)
output2 = json.dumps(output1, indent=4)

or can you guys tell me where can i find the pullbranch analysis report locally where sonar-scanner is running because it pulls from server right and posts comments to gerrit server?

Hi,

Have you tried this via the UI? The best way to master the API is to perform the desired action via the UI and eavesdrop to see which calls the UI made to accomplish the action.

You may also find this guide helpful.

 
HTH,
Ann

Yes, i tried the gui and i am seeing that i am getting 404 response to curl call and same call works on mac. so on linux how should i construct my call because my setup is on jenkins.

    sq_url='https://sonar-sw.team.com/api/'
    url="${sq_url}qualitygates/project_status?projectKey=aiinfra-pba&pullRequest=${GERRIT_CHANGE_NUMBER}-${GERRIT_PATCHSET_NUMBER}"
    curl -vvv -u "${Main_TOKEN}": "$url"

so is there a specific format to follow for making curl call on linux as same works on mac?

jenkins logs shows 404.

* Connected to sonar-sw.team.com (10.7.77.103) port 443 (#0)

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs

* ALPN, server accepted to use http/1.1

*  issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS RSA SHA256 2020 CA1
*  SSL certificate verify ok.
* Server auth using Basic with user ****
} [5 bytes data]
> GET /api/qualitygates/project_status?projectKey=pba&pullRequest=124434-59 HTTP/1.1
> Host: sonar-sw.nvidia.com
> Authorization: Basic xxxx=
> User-Agent: curl/7.68.0
> Accept: */*
> 
{ [5 bytes data]
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 
< Server: nginx/1.12.2
< Date: Fri, 24 Mar 2023 18:15:03 GMT
< Content-Type: application/json
< Content-Length: 102
< Connection: keep-alive
< 
{ [102 bytes data]

100   102  100   102    0     0    126      0 --:--:-- --:--:-- --:--:--   126
* Connection #0 to host sonar-sw.nvidia.com left intact
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   102  100   102    0     0    127      0 --:--:-- --:--:-- --:--:--   126
jq: error (at <stdin>:0): Cannot iterate over null (null)
[Pipeline] echo
{"errors":[{"msg"

Hi,

I wouldn’t expect the format to be different, but I’m not a curl expert. Maybe the man pages will help.

 
Ann