# -*- coding: UTF-8 -*-
import requests
import json
import xlwt
import xlrd
from xlrd import open_workbook
import openpyxl
from xlutils.copy import copy
count=0
import datetime
#获取所有项目key
url="http://10.119.169.6:9000/api/components/search_projects?ps=500&facets=reliability_rating%2Csecurity_rating%2Csqale_rating%2Ccoverage%2Cduplicated_lines_density%2Cncloc%2Calert_status%2Clanguages%2Ctags&f=analysisDate%2CleakPeriodDate&s=analysisDate&asc=false"
#根据项目key查询项目信息
ResultURL="http://10.119.169.6:9000/api/measures/component?additionalFields=metrics%2Cperiods&componentKey="
Params = "&metricKeys=alert_status%2Cbugs%2Cnew_bugs%2Creliability_rating%2Cnew_reliability_rating%2Cvulnerabilities%2Cnew_vulnerabilities%2Csecurity_rating%2Cnew_security_rating%2Ccode_smells%2Cnew_code_smells%2Cnew_technical_debt%2Ccoverage%2Cnew_coverage%2Cnew_lines_to_cover%2Cduplicated_lines_density%2Cnew_duplicated_lines_density%2Cduplicated_blocks%2Cnew_lines%2Cncloc"
#根据项目key查询bug等级接口
BugDefineURL="http://10.119.169.6:9000/api/issues/search?componentKeys="
BugDefineParams="&s=FILE_LINE&resolved=false&ps=100&facets=severities%2Ctypes&additionalFields=_all"
#查询扫描间隔
ScanperiodURL="http://10.119.169.6:9000/api/project_analyses/search?project="
ScanperiodParams="&ps=2"
#生成文件名称
filepath = 'SonarQube_Analysis.xls'
if __name__=='__main__':
rsp = requests.get(url)
JStext = json.loads(rsp.text)
#定义空列表
RPkey = []
a = []
#获取项目key
for i in JStext['components']:
x=i['key']
#取出项目key
RPkey.append(x)
#新建excel
workbook = xlwt.Workbook(encoding='utf-8')
ws = workbook.add_sheet('Sonar')
#定义excel首行
ws.write(0,0,'ProjectName')
ws.write(0,1,'alert_status')
ws.write(0,2,'bugs')
ws.write(0,3,'new_bugs')
ws.write(0,4,'code_smells')
ws.write(0,5,'new_code_smells')
ws.write(<
获取sonarqube项目信息
最新推荐文章于 2022-09-08 09:45:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)