您好,我剛剛發現了 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中文網其他相關文章!