您好,我刚刚发现了 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 票证管理的详细内容。更多信息请关注PHP中文网其他相关文章!