-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcollect_bug_report.py
77 lines (64 loc) · 3.28 KB
/
collect_bug_report.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
# -*-coding:utf-8-*-
# The script has been tested successfully.
from helper.config import projects
from helper.file_helper import *
from jira import JIRAError
from jira.client import JIRA
def collect_bugs(proj):
"""
Collect Bug reports data from JIRA ITS
"""
jira = JIRA(server="https://issues.apache.org/jira/", auth=('user', 'password'))
statistics_path = root_path + '/BugReport/'
reports_path = root_path + '/BugReport/reports/' + proj + '/'
make_path(statistics_path)
make_path(reports_path)
text = 'id, Key, Type, Status, Resolution, Priority, AffectsVersions, FixedVersions, Reporter, Creator,' \
' Assignee, CreatedDate, ResolutionDate, UpdatedDate, Summary\n'
search_str = 'project = ' + proj.upper() + ' AND issuetype = Bug AND status in (Resolved, Closed) AND ' \
'resolution in (Fixed, Resolved) ORDER BY key ASC'
start = 0
max_results_each_search = 1000
while True:
issues = jira.search_issues(search_str, startAt=start, maxResults=max_results_each_search)
for issue in issues:
try:
reporter_name = 'Unassigned' if issue.fields.reporter is None else issue.fields.reporter.displayName
creator_name = 'Unassigned' if issue.fields.creator is None else issue.fields.creator.displayName
assignee_name = 'Unassigned' if issue.fields.assignee is None else issue.fields.assignee.displayName
# Record each bug report information
text += issue.id + ','
text += issue.key + ','
text += issue.fields.issuetype.name + ','
text += issue.fields.status.name + ','
text += issue.fields.resolution.name + ','
text += issue.fields.priority.name + ','
text += '|'.join([version.name for version in issue.fields.versions]) + ','
text += '|'.join([version.name for version in issue.fields.fixVersions]) + ','
text += reporter_name + ','
text += creator_name + ','
text += assignee_name + ','
text += issue.fields.created + ','
text += issue.fields.resolutiondate + ','
text += issue.fields.updated + ','
text += issue.fields.summary.replace('\n', ' ') + '\n'
# Output the text content of each bug report to a file
text_content = 'XXX Summary XXX\n' + issue.fields.summary.replace('\n', ' ') + '\nXXX Description XXX\n'
text_content += '' if issue.fields.description is None else issue.fields.description
save_data_to_file(reports_path + issue.key + '.txt', text_content)
except JIRAError:
continue
except TypeError:
continue
except AttributeError:
continue
start += max_results_each_search
print(start, issues.total)
if start >= issues.total:
break
# Output the statistics information of the project
save_data_to_file(statistics_path + proj + '.csv', text)
print('The collection for bug reports of Project ' + proj + ' has finished!')
if __name__ == '__main__':
for project in projects:
collect_bugs(project)