Closed abcanqi closed 3 years ago
from pprint import pprint from operator import itemgetter from itertools import groupby from sonarqube import SonarQubeClient
def group_by_order(issues, order): """ 按照order分组issues :param issues: :param order: :return: """ issues = [item for item in issues if order in item] groupby_issues = {} issues = sorted(issues, key=itemgetter(order)) for issue_order, items in groupby(issues, key=itemgetter(order)): if issue_order: groupby_issues[issue_order] = list(items) return groupby_issues
def generate_issue_numbers(issues, order): """ 通过order对issues进行分组计数 :param issues: :param order: :return: """ groupby_issues = group_by_order(issues, order) return {key: len(values) for key, values in groupby_issues.items()}
if name == "main": sonarqube_url = 'http://*.*.*.*.9000' username = "admin" password = "admin" sonarhandler = SonarQubeClient(sonarqube_url=sonarqube_url, username=username, password=password) issues = sonarhandler.issues.search_issues(componentKeys="myproject", branch="master") result = generate_issue_numbers(issues, "severity") pprint(result)
试试上面代码, 使用generate_issue_numbers 函数对search_issues 得到的issues结果进行按类别统计格式。 参考结果
您的方法解决了我的问题,谢谢作者!
我想统计不同严重程度 Issue 的个数,但是您的代码里好像只读取了issue列表,没有将其它返回值拿出来,能否增加一下该功能呢?