质量可靠
品质保障,精益求精
\
您好,我刚刚发现了 jira lib,我决定对其进行测试,以找到获得最多门票的人。
我的github中的代码:https://github.com/victordalet/jira_python_test
你只需要python并安装jira lib。
pip install jira
用您的信息声明 3 个变量,并在安全中前往 https://id.atlassian.com/manage-profile/profile-and-visibility 生成您的令牌(密码)。
jira_url = "" # https://name.alassian.net jira_user = "" # me@name.fr jira_password = "" # token
我正在创建一个类来获取jira信息,它可以创建一种类似于get_tickets方法的mysql查询来查找资源或票证、项目...
class ticketmanager: def __init__(self): self.jira = jira(jira_url, basic_auth=(jira_user, jira_password)) def get_projects(self): return self.jira.projects() def get_tickets(self, project_key: str): return self.jira.search_issues(f'project="{project_key}"') @staticmethod def ticket_status(ticket_): return ticket_.fields.status @staticmethod def ticket_reporter(ticket_): try: return ticket_.fields.reporter except attributeerror: return "unknown" @staticmethod def ticket_assignee(ticket_): try: return ticket_.fields.assignee except attributeerror: return "unknown"
我浏览该项目以找到所有门票并将正确的雕像添加到用户字典中。
if __name__ == '__main__': ticket_manager = ticketmanager() projects = ticket_manager.get_projects() user = {} nb_total_tickets = 0 for project in projects: tickets = ticket_manager.get_tickets(project.key) nb_total_tickets += len(tickets) for ticket in tickets: reporter = ticket_manager.ticket_reporter(ticket) assignee = ticket_manager.ticket_assignee(ticket) if assignee not in user: user[assignee] = {'ticket_to_do': 0, 'ticket_reported': 0} if reporter not in user: user[reporter] = {'ticket_to_do': 0, 'ticket_reported': 0} user[assignee]['ticket_to_do'] += 1 user[reporter]['ticket_reported'] += 1 print(f'there are {nb_total_tickets} tickets in total')
现在我按照创建和使用的票证数量对用户进行排序。
user = dict(sorted(user.items(), key=lambda x: (x[1]['ticket_to_do'], x[1]['ticket_reported']), reverse=true)) for name, value in user.items(): print(f'{name} : {value["ticket_to_do"]} tickets to do, {value["ticket_reported"]} tickets reported')
结果:
J.M. : 90 tickets to do, 60 tickets reported L.M : 75 tickets to do, 21 tickets reported J.M : 57 tickets to do, 76 tickets reported V.M : 50 tickets to do, 0 tickets reported
以上就是Python-Jira 票证管理的详细内容,更多请关注本网内其它相关文章!