-
Notifications
You must be signed in to change notification settings - Fork 1
/
jiraexporter.py
53 lines (37 loc) · 1.41 KB
/
jiraexporter.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
#!/usr/bin/env python
""" Export tool for extracting all jira issues from a given project
"""
import json
from jira import JIRA
JIRA_URL = 'https://jira.mongodb.org'
PROJECT = 'SERVER'
OUTPUT_FILE = 'issues.json'
BASIC_AUTH = ('', '')
class JiraIssueExporter(object):
def __init__(self, jira_url=JIRA_URL, project=PROJECT,
basic_auth=BASIC_AUTH):
self.jira_url = JIRA_URL
self.project = project
self.all_issues = []
self.jira = JIRA(jira_url, basic_auth=basic_auth)
self.raw_issues = []
def fetch_issues(self, startAt=0, maxResults=1000):
jqlStr = 'project=%s ORDER BY key ASC' % self.project
while True:
issues = self.jira.search_issues(jqlStr, startAt=startAt,
maxResults=maxResults)
if len(issues) == 0:
print 'no new issues..'
break
print 'fetched results: %s' % issues[-1].key
startAt += maxResults
self.all_issues.extend(issues)
self.__store_raw_issues()
def __store_raw_issues(self):
if self.raw_issues != []:
raise Exception('raw issues already exist')
for issue in self.all_issues:
self.raw_issues.append(issue.raw)
def dump_json(self, output_file=OUTPUT_FILE):
with open(output_file, 'w') as fp:
json.dump(self.raw_issues, fp)