-
Notifications
You must be signed in to change notification settings - Fork 3
/
github-issue-exporter.py
164 lines (138 loc) · 7.14 KB
/
github-issue-exporter.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"""
Exports issues from a repository to csv files.
Uses basic authentication (Github username + password) to retrieve issues
from a repository that username has access to. Supports Github API v3.
Forked from: unbracketed/export_repo_issues_to_csv.py
"""
import csv
import requests
import datetime
import json
type_is = ' is:issue'
#milestone = '4.1'
repo = 'management-center'
#query_milestone = 'milestone:' + milestone
query_repo = 'repo:hazelcast/' + repo
# Search query with milestone filter
# search_query = ' ' + type_is + ' ' + query_milestone + ' ' + query_repo
# Search query without milestone filter
search_query = ' ' + type_is + ' ' + query_repo + ' is:open'
github_user = 'YOUR-GH-USERNAME'
github_token = 'YOUR-GH-TOKEN'
issue_count = 0
conversion_dict = {'emre-aydin': '[email protected]',
'jgardiner68': '[email protected]',
'puzpuzpuz': '[email protected]',
'neilstevenson': '[email protected]',
'yuraku': '[email protected]',
'aigoncharov': '[email protected]',
'jbee': '[email protected]',
'vertex-github': '[email protected]',
'erosb': '[email protected]',
'olukas': '[email protected]',
'alex-dukhno': '[email protected]',
'jerrinot': '[email protected]',
'dbrimley': '[email protected]',
'danad02': '[email protected]',
'utkukaratas': '[email protected]',
'jankoritak': '[email protected]',
'sertugkaya': '[email protected]',
'alparslanavci': '[email protected]',
'tezc': '[email protected]',
'pjastrz': '[email protected]',
'jvorcak': '[email protected]',
'Holmistr': '[email protected]',
'gurbuzali': '[email protected]',
'gokhanoner': '[email protected]',
'pawelklasa': '[email protected]',
'ncherkas': '[email protected]',
'mesutcelik': '[email protected]',
'viliam-durina': '[email protected]',
'Serdaro': '[email protected]',
'nfrankel': '[email protected]',
'mmedenjak': '[email protected]',
'mdumandag': '[email protected]',
'lazerion': '[email protected]',
'kairojya':'[email protected]',
'jahanzebbaber': '[email protected]',
'hasancelik': '[email protected]',
'eminn': '[email protected]',
'burakcelebi': '[email protected]',
'bilalyasar': '[email protected]',
'bbuyukormeci': '[email protected]',
'7erry': '[email protected]',
'': ''}
def get_issues():
# Requests issues from GitHub API and writes to CSV file.
result_json = requests.get('https://api.github.com/search/issues',
auth=(github_user, github_token),
params={'q': search_query, 'sort': 'updated', 'direction': 'desc'})
print("Function starts:", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
csvfilename = '/Users/ayberksorgun/Desktop/github-issues/{}-issues-{}.csv' \
.format(repo, datetime.datetime.now().strftime("%Y-%m-%dt%H-%M-%S"))
print('Filename: ', csvfilename)
with open(csvfilename, 'w', newline='') as csvfile:
csv_out = csv.writer(csvfile)
csv_out.writerow(['Summary', 'Description', 'dateCreated', 'fixVersion', 'Creator', 'Assignee', 'Comments', 'Labels'])
write_issues(result_json, csv_out)
# Multiple requests are required if response is paged
if 'link' in result_json.headers:
pages = {rel[6:-1]: url[url.index('<') + 1:-1] for url, rel in
(link.split(';') for link in result_json.headers['link'].split(','))}
while 'last' in pages and 'next' in pages:
pages = {rel[6:-1]: url[url.index('<') + 1:-1]
for url, rel in (link.split(';')
for link in result_json.headers['link'].split(','))}
result_json = requests.get(pages['next'], auth=(github_user, github_token))
write_issues(result_json, csv_out)
if pages['next'] == pages['last']:
break
print("Function ends : ", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print('Total number of issues imported:', issue_count)
def write_issues(result_json, csvout):
# Parses JSON response and writes to CSV file
if result_json.status_code != 200:
raise Exception(result_json.status_code)
for item in result_json.json()['items']:
labels = [l['name'] for l in item['labels']]
# Creation date of the issue
create_date = item['created_at'].split('T')[0]
# Close date of the issue
close_date = item['closed_at']
# If there is a close date then split the date and only include the date part but not time
if close_date:
close_date = close_date.split('T')[0]
# Assignee information
assignee_str = ''
# If issue has assignee then get the login name of the assignee
if item['assignee'] is not None:
assignee = item['assignee']
if assignee is not None:
assignee_str = assignee['login']
# User that opened the issue
user_str = ''
# Get the login name of the user who opened the issue
if item['user'] is not None:
user = item['user']
if user is not None:
user_str = user['login']
milestone_str = ''
# Get the milestone label of the issue
if item['milestone'] is not None:
milestone = item['milestone']
if milestone is not None:
milestone_str = milestone['title']
# Getting comment information by using another GET request
comment_json = requests.get('https://api.github.com/repos/hazelcast/management-center/issues/' +
str(item['number']) + '/comments', auth=(github_user, github_token))
# Creating a list of comments for every issue
comments = [each['created_at'].split('T')[0] + ' ' + each['created_at'].split('T')[1][0:5] + '; ' +
conversion_dict[each['user']['login']] + '; ' + each['body'] for each in comment_json.json()]
# Change the following line to write out additional fields
csvout.writerow([item['title'], "GH Issue link: "+item['html_url'] + " \\"+"\\" + item['body'], create_date,
milestone_str, conversion_dict[user_str], conversion_dict[assignee_str], json.dumps(comments),
labels])
# Counting the number of issues
global issue_count
issue_count += 1
get_issues()