Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

get request using a script python and web API in sonarQUbe

I'v recently started using sonar.cloud.whatever.com. on the profolio I have by default the analysisi result for a master branch by default for any given project so if I need to collect the information for multiple branched in this project I have to select those branched one by one. For the moment I don't know if there is any other simple way to do this without given by sonar so I stated a script on python using the webservice API given by sonar . I stated (just to try the result) by collecting all the issues using /api/issues/search

import json
import sys
import os
import requests
def usage():

    print("hello")
 
def collectIssues():
    r=requests.get('https://sonar.cloud.sec.NotToMention.com/api/issues/search? componentKeys=project_key&statuses=OPEN')
    print("le code ",r.status_code)
    print(r.url)
    #print(r.headers)
    if(r.status_code!=200):
        exit(0)
    
    data=r.json() 
    print(r.headers,"

")
    print(data)
    print(data['issues'])  
 
def main(args):
 
    collectIssues()
 
if __name__== '__main__':
 
    main(sys.argv)
    exit(0)

if I copy the link and browse it I have the right result with total 1000 issues, but the result of this script gives total 0 and issues = [].

(I want just to sign that project_name and NotToMention are not the real values I replaced them here for security issues.)

the result of this script is :

status_code : 200

https://sonar.cloud.NotTOMention.com/api/issues/search?componentKeys=project_name&statuses=OPEN

JSON RESULT :

{'total': 0, 'p': 1, 'ps': 100, 'paging': {'pageIndex': 1, 'pageSize': 100, 'total': 0}, 'effortTotal': 0, 'debtTotal': 0, 'issues': [], 'components': [], 'facets': []}

thanks for any advice.

best regards

question from:https://stackoverflow.com/questions/65846621/get-request-using-a-script-python-and-web-api-in-sonarqube

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...