-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_sf.py
executable file
·134 lines (115 loc) · 4.09 KB
/
import_sf.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
#!/usr/bin/env python
#
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# Joerg Wunsch wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return. Joerg Wunsch
# ----------------------------------------------------------------------------
#
"""
import_sf.py - Helper to import SourceForge.net issue trackers to GitHub
This operates on a SourceForge.net project export.
Unpack it into a temporary directory. All issue trackers can be found
there in separate JSON files named <issuetype>.json. This script
operates on such a JSON file, and generates a JSON file equivalent to
what savane2github.py produces after step #3.
./import_sf.py /some/temp/dir/project-backup-date/bugs.json \
> project/trackers_bugs.json
Use savane2github.py then to import it to GitHub:
./savane2github.py --username user --project project \
--access-token ghp_xxxxxxxxxxxxxxxxxx --repo-path where/project \
--export-bugs
"""
import json
import sys
import re
def map_status(s):
"map SF.net status to Savannah status and resolution"
# closed_status_names:
# closed wont-fix closed-invalid closed-fixed closed-works-for-me
# open_status_names
# open unread accepted pending
if s == 'closed':
return ('Closed', 'Fixed')
if s == 'wont-fix' or s == 'closed-wont-fix':
return ('Closed', 'Wont Fix')
if s == 'closed-invalid':
return ('Closed', 'Invalid')
if s == 'closed-fixed':
return ('Closed', 'Fixed')
if s == 'closed-works-for-me':
return ('Closed', 'Works For Me')
if s == 'closed-duplicate':
return ('Closed', 'Duplicate')
if s == 'open' or s == 'unread' or s == 'accepted':
return ('Open', 'None')
if s == 'pending':
return ('Open', 'In Progress')
return ('Open', 'None') # not supposed to happen
def cleanup(s):
"Remove unneeded backslashes from text"
s = s.replace('<', '<')
s = s.replace('>', '>')
pat1 = re.compile(r'\\([-+*_{}()])')
return pat1.sub('\g<1>', s)
if len(sys.argv) <= 1:
sys.stderr.write("usage: import_sf.py <filename>\n")
sys.exit(1)
f = open(sys.argv[1])
j = json.load(f)
f.close()
urlbase = 'https://sourceforge.net' + j['tracker_config']['options']['url']
issuetype = j['tracker_config']['options']['mount_point']
# 'mount_point' is 'bugs', 'patches' and so on -> turn into singular
if issuetype.endswith('es'):
issuetype = issuetype[:-2]
elif issuetype.endswith('s'):
issuetype = issuetype[:-1]
result = []
tickets = j['tickets']
for t in tickets:
o = {} # o = "output"
o['_json_type'] = 'Tracker'
o['migration_id'] = None
o['migration_status'] = 'pending'
o['type'] = issuetype
o['item_id'] = t['ticket_num']
o['url'] = urlbase + str(t['ticket_num']) + '/'
o['summary'] = t['summary']
(s, r) = map_status(t['status'])
o['status_id'] = s
o['resolution_id'] = r
o['originator_name'] = t['reported_by']
o['originator_email'] = None
o['summary'] = cleanup(t['summary'])
o['description'] = {
'_json_type': 'TrackerComment',
'migration_status': 'pending',
'author': None,
'time': t['created_date'],
'text': cleanup(t['description'])
}
comments = []
attachments = []
for p in t['discussion_thread']['posts']:
if len(p['text']) > 0:
c = {
'_json_type': 'TrackerComment',
'migration_status': 'pending',
'author': p['author'],
'time': p['timestamp'],
'text': cleanup(p['text'])
}
comments.append(c)
for a in p['attachments']:
at = {
'_json_type': 'TrackerAttachment',
'text': a['path'].split('/')[-1],
'url': a['url']
}
attachments.append(at)
o['comments'] = comments
o['attachments'] = attachments
result.append(o)
print(json.dumps(result, indent=4))