-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff2issues.py
55 lines (47 loc) · 1.38 KB
/
diff2issues.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
# -*- coding: utf-8 -*-
import sys
import json
import time
import urllib2
token = ''
user = 'django-docs-ja'
repo = 'django-docs-ja'
milestone = 1
labels = ['enhancement']
start = 'Index: '
protocol = 'https'
domain = 'api.github.com'
issues_url = '/'.join(('%s://%s' % (protocol, domain), 'repos', user, repo,
'issues'))
def create_issue(title, body, milestone, labels):
issue = {
'title': title,
'body': body,
'milestone': milestone,
'labels': labels,
}
data = json.dumps(issue)
request = urllib2.Request(issues_url, data=data)
request.add_header('Authorization', 'token %s' % token)
request.get_method = lambda: 'POST'
response = urllib2.urlopen(request)
return response.code == 201
def main():
filename = None
lines = []
for line in file(sys.argv[1]):
line = line.strip()
line = line.decode('utf-8', 'replace')
if line.startswith(start):
if lines:
diff = '```\n%s\n```' % '\n'.join(lines)
success = create_issue(filename, diff, milestone, labels)
if not success:
sys.stderr.write('failed to create issue: %s\n' % filename)
filename = None
lines = []
filename = line[len(start):]
if filename:
lines.append(line)
if __name__ == '__main__':
main()