This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert.py
70 lines (57 loc) · 1.67 KB
/
convert.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
#!/usr/bin/env python
import csv
import json
import urllib
USERNAME = ''
ORGNAME = ''
PROJECT = ''
AUTH_TOKEN = ''
TRAC_URL = 'http://example.com/trac/report/1?format=csv'
TAGS = []
if (ORGNAME == ''):
ORGNAME = USERNAME
github_url = 'https://github.com/api/v2/json/issues/'
csv_data = urllib.urlopen(TRAC_URL)
reader = csv.DictReader(csv_data)
tickets = []
url = github_url + 'list/%s/%s/open' % (ORGNAME, PROJECT)
data = urllib.urlencode({
'login': USERNAME,
'token': AUTH_TOKEN,
})
response = urllib.urlopen(url, data)
content = response.read()
issues = json.loads(content)['issues']
for row in reader:
for key, value in row.items():
row[key] = row[key].decode('utf-8')
if filter(lambda i: i['title'] == row['summary'], issues):
continue
tickets.append({
'title': row['summary'],
'description': row['_description'],
'tags': [row['type'], row['component']] + TAGS,
})
for ticket in tickets:
url = github_url + 'open/%s/%s' % (ORGNAME, PROJECT)
data = urllib.urlencode({
'login': USERNAME,
'token': AUTH_TOKEN,
'title': ticket['title'].encode('utf-8'),
'body': ticket['description'].encode('utf-8'),
})
urllib.urlopen(github_url, data)
response = urllib.urlopen(url, data)
content = response.read()
try:
issue = json.loads(content)['issue']
except KeyError:
raise Exception(content)
data = urllib.urlencode({
'login': USERNAME,
'token': AUTH_TOKEN,
})
for tag in ticket['tags']:
url = github_url + 'label/add/%s/%s/%s/%s' % (
ORGNAME, PROJECT, tag, issue['number'])
urllib.urlopen(url, data)