1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| import json from functools import reduce
import requests from prettytable import PrettyTable
token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' headers = { "Authorization": "Bearer %s" % token, "Accept": "application/json, text/plain, */*", "Content-Type": "application/json;charset=UTF-8", } duiring_time = "2022-01-01, 2023-01-01" jira_user_accounts = [ 'zhangsan', 'lisi', 'wangwu' ]
if __name__ == '__main__': requests.packages.urllib3.disable_warnings() total_result = [] for jira_user in jira_user_accounts: params = { "startAt": 0, "maxResults": 2000, "jql": "project = CSFS AND status changed to resolved by (%s) during (%s)" % (jira_user, duiring_time), "fields": ['customfield_40669'] } res = requests.post("https://jiradc2.ext.net.nokia.com/rest/api/2/search", headers=headers, data=json.dumps(params, ensure_ascii=False).encode("utf-8"), verify=False) issues = res.json()['issues'] if len(issues) > 0: display_name = "Unknown" try: for issue in issues: resolve_users = issue['fields']["customfield_40669"] for resolve_user in resolve_users: if resolve_user['name'] == jira_user: display_name = resolve_user["displayName"] raise StopIteration except StopIteration: total_result.append({"name": jira_user, 'count': len(issues), "display_name": display_name}) else: total_result.append({"name": jira_user, 'count': 0})
total_result.sort(key=lambda u: u["count"], reverse=True)
total_count = reduce(lambda x, y: x + y["count"], total_result, 0) print("total: " + str(total_count)) myTable = PrettyTable(["user", "display name", "count"]) for result in total_result: if 'display_name' in result: myTable.add_row([result['name'], result['display_name'], result['count']]) else: myTable.add_row([result['name'], '', result['count']]) print(myTable)
|