-
Notifications
You must be signed in to change notification settings - Fork 0
/
arij.py
executable file
·137 lines (105 loc) · 3.55 KB
/
arij.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
from jira import JIRA
class JiraProject:
"""
Client in charge to retrieve all issues and comments
for a given JIRA project
"""
def __init__(self, jira_url, project_key):
self.jira_url = jira_url
self.jira_client = JIRA(
options={'server': self.jira_url, 'verify': False},
validate=False)
self.project_key = project_key
def get_comments(self, issue):
return self.jira_client.issue(issue.key, expand='comments')
def get_project_versions(self):
return self.jira_client.project_versions(self.project_key)
@staticmethod
def get_attachments(issue):
try:
return issue.fields.attachment
except AttributeError:
return None
@staticmethod
def get_assignee(issue):
try:
return issue.fields.assignee.name
except AttributeError:
return None
@staticmethod
def get_creation_datetime(issue):
return issue.fields.created
@staticmethod
def get_fix_version(issue):
try:
fix_versions = issue.fields.fixVersions
if len(fix_versions) > 0:
return fix_versions[0].name
else:
return None
except AttributeError:
return None
@staticmethod
def get_priority(issue):
try:
return issue.fields.priority.name
except AttributeError:
return None
@staticmethod
def get_resolution(issue):
if issue.fields.resolution is not None:
return issue.fields.resolution.name
else:
return None
@staticmethod
def get_title(issue):
return issue.fields.summary
@staticmethod
def get_type(issue):
return issue.fields.issuetype.name
@staticmethod
def is_closed(issue):
return issue.fields.resolution is not None
def get_issues(self):
start_index = 0
max_nb_results = 100
result = []
# while start_index < max_nb_results:
while True:
issues = self.jira_client.search_issues(
'project=' + self.project_key,
startAt=start_index,
maxResults=max_nb_results)
result.extend(issues)
if len(issues) == 0 or len(issues) < max_nb_results:
break
else:
start_index += max_nb_results
return sorted(result, key=lambda issue: int(
issue.key[issue.key.index('-') + 1:]))
def get_attachment_information(self):
start_index = 0
max_nb_results = 100
result = []
# while start_index < max_nb_results \
while True:
issues = self.jira_client.search_issues(
'project=' + self.project_key,
fields='attachment',
startAt=start_index,
maxResults=max_nb_results)
for issue in issues:
a = self.get_attachments(issue)
if a is not None and len(a) > 0:
[result.append((issue.key, v.id)) for v in a]
if len(issues) == 0 or len(issues) < max_nb_results:
break
else:
start_index += max_nb_results
return result
def get_attachment(self, attachment_id):
return self.jira_client.attachment(attachment_id)
if __name__ == '__main__':
jira = JiraProject('https://jira.activeeon.com', 'SCHEDULING')
print("Attachment ids -> ", str(jira.get_attachment_information()))