forked from wogscpar/SZZUnleashed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.py
66 lines (54 loc) · 2.39 KB
/
fetch.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
""" Fetch issues that match given jql query """
__author__ = "Kristian Berg"
__copyright__ = "Copyright (c) 2018 Axis Communications AB"
__license__ = "MIT"
from urllib.parse import quote
import urllib.request as url
import json
import os
import argparse
import io
import sys
def fetch(project_issue_code, jira_project_name):
""" Fetch issues that match given jql query """
# Jira Query Language string which filters for resolved issues of type bug
jql = 'project = ' + project_issue_code + ' ' \
+ 'AND issuetype = Bug '\
+ 'AND status in (Resolved, Closed) '\
+ 'AND resolution = Fixed '\
+ 'AND component = core '\
+ 'AND created <= "2018-02-20 10:34" '\
+ 'ORDER BY created DESC'
jql = quote(jql, safe='')
start_at = 0
# max_results parameter is capped at 1000, specifying a higher value will
# still return only the first 1000 results
max_results = 1000
os.makedirs('issues/', exist_ok=True)
request = 'https://' + jira_project_name + '/rest/api/2/search?'\
+ 'jql={}&start_at={}&max_results={}'
# Do small request to establish value of 'total'
with url.urlopen(request.format(jql, start_at, '1')) as conn:
contents = json.loads(conn.read().decode('utf-8'))
total = contents['total']
# Fetch all matching issues and write to file(s)
print('Total issue matches: ' + str(total))
print('Progress: | = ' + str(max_results) + ' issues')
while start_at < total:
with url.urlopen(request.format(jql, start_at, max_results)) as conn:
with io.open('issues/res' + str(start_at) + '.json', 'w', encoding="utf-8") as f:
f.write(conn.read().decode('utf-8', 'ignore'))
print('|', end='', flush='True')
start_at += max_results
print('\nDone!')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="""Convert a git log output to json.
""")
parser.add_argument('--issue-code', type=str,
help="The code used for the project issues on JIRA: e.g., JENKINS-1123. Only JENKINS needs to be passed as parameter.")
parser.add_argument('--jira-project', type=str,
help="The name of the Jira repository of the project.")
args = parser.parse_args()
project_issue_code = args.issue_code
jira_project_name = args.jira_project
fetch(project_issue_code, jira_project_name)