您好,我剛剛發現了 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 = "" # [email protected] 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
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3