-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjira_client.py
89 lines (73 loc) · 3.19 KB
/
jira_client.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
Modulo de interacao com o JIRA
"""
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
from jira import JIRA
class JiraClient:
def __init__(self, api_token, server_url, user_email):
self.client = JIRA(
server=server_url,
basic_auth=(user_email, api_token)
)
def check_connectivity(self):
"""
Verifica a conectividade com o servidor JIRA.
:return: True se a conexão for bem-sucedida, False caso contrário.
"""
try:
# Realiza uma chamada simples para verificar a conexão.
self.client.myself()
return True
except Exception as e:
print(f"Erro de conectividade com o Jira: {e}")
return False
def check_wip_limit(self, board_id, wip_limit, states):
"""
Verifica se o limite de WIP foi atingido para o board e estados especificados.
:param board_id: ID do board no JIRA.
:param wip_limit: Limite de WIP.
:param states: Lista de estados a serem verificados.
:return: True se o limite de WIP for atingido, False caso contrário.
"""
jql = f'board = {board_id} AND status in ({",".join(states)})'
issues = self.client.search_issues(jql)
return len(issues) > wip_limit
def check_progress_status(self, epic_id, label):
"""
Informa semanalmente o status de progresso de um epic_id,
ou um label para pesquisa (que identifica o marco de entrega)
:param epic_id: The epic ID to monitor (e.g., 'BURACO-4245')
:param label: The label identifying the delivery milestone (e.g., 'Milestone_1')
:return: A dictionary with total and completed issues, or an error message.
"""
if not label or not epic_id:
return {"error": "Label and epic_id are required parameters."}
try:
# Query for all issues matching the epic_id and label
jql = f'parent = "{epic_id}" AND status not in (Cancelled, Aborted) AND labels = "{label}"'
issues = self.client.search_issues(jql, maxResults=False)
count_total = len(issues)
# Query for completed issues
jql_done = f'parent = "{epic_id}" AND status = Done AND labels = "{label}"'
issues_done = self.client.search_issues(jql_done, maxResults=False)
count_done = len(issues_done)
# Build progress status
progress_status = {"total_issues": count_total,
"done_issues": count_done}
except Exception as e:
return {"error": str(e), "total_issues": 0, "done_issues": 0}
return progress_status
def get_epic_summary(self, epic_id):
"""
Obtém o título (summary) de um épico pelo ID.
:param epic_id: O ID do épico no JIRA.
:return: O título (summary) do épico, ou None em caso de erro.
"""
try:
issue = self.client.issue(epic_id)
return issue.fields.summary
except Exception as e:
print(f"Erro ao buscar o summary do épico {epic_id}: {e}")
return None