forked from arthur-debert/google-code-issues-migrator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate-issues
More file actions
executable file
·118 lines (95 loc) · 3.9 KB
/
migrate-issues
File metadata and controls
executable file
·118 lines (95 loc) · 3.9 KB
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
#!/usr/bin/env python
import optparse
import sys
import re
import logging
import datetime
import dateutil.parser
from github2.client import Github
import gdata.projecthosting.client
import gdata.projecthosting.data
import gdata.gauth
import gdata.client
import gdata.data
import atom.http_core
import atom.core
GITHUB_REQUESTS_PER_SECOND = 0.5
GOOGLE_MAX_RESULTS = 25
logging.basicConfig(level=logging.ERROR)
def output(string):
sys.stdout.write(string)
sys.stdout.flush()
def add_issue_to_github(issue):
id = re.search('\d+$', issue.id.text).group(0)
title = issue.title.text
link = issue.link[1].href
content = issue.content.text
body = '<pre>%s</pre><br>Original link: %s' % (content, link)
output('Adding issue %s' % (id))
github_issue = None
if options.dry_run is not True:
github_issue = github.issues.open(github_project, title=title, body=body.encode('utf-8'))
github.issues.add_label(github_project, github_issue.number, "imported")
if issue.status.text.lower() in "invalid closed fixed wontfix verified done duplicate".lower():
if options.dry_run is not True:
github.issues.close(github_project, github_issue.number)
# Add any labels
if len(issue.label) > 0:
output(', adding labels')
for label in issue.label:
if options.dry_run is not True:
github.issues.add_label(github_project, github_issue.number, label.text.encode('utf-8'))
output('.')
# Add any comments
start_index = 1
max_results = GOOGLE_MAX_RESULTS
while True:
comments_feed = google.get_comments(google_project_name, id, query=gdata.projecthosting.client.Query(start_index=start_index, max_results=max_results))
if len(comments_feed.entry) is 0:
break;
if start_index is 1:
output(', adding comments')
for comment in comments_feed.entry:
add_comment_to_github(comment, github_issue)
output('.')
start_index += max_results
output('\n')
def add_comment_to_github(comment, github_issue):
id = re.search('\d+$', comment.id.text).group(0)
link = comment.link[0].href
author = comment.author[0].name.text
date = dateutil.parser.parse(comment.published.text).strftime('%B %d, %Y %H:%M:%S')
content = comment.content.text
body = '%s on %s:<br><pre>%s</pre><br>Original link: %s'% (author, date, content, link)
logging.info('Adding comment %s', id)
if options.dry_run is not True:
github.issues.comment(github_project, github_issue.number, body.encode('utf-8'))
def process_issues():
start_index = 1
max_results = GOOGLE_MAX_RESULTS
while True:
issues_feed = google.get_issues(google_project_name, query=gdata.projecthosting.client.Query(start_index=start_index, max_results=max_results))
if len(issues_feed.entry) is 0:
break;
for issue in issues_feed.entry:
add_issue_to_github(issue)
start_index += max_results
if __name__ == "__main__":
usage = "usage: %prog [options] <google_project_name> <github_api_token> <github_user_name> <github_project>"
description = "Migrate all issues from a Google Code project to a Github project."
parser = optparse.OptionParser(usage=usage, description=description)
parser.add_option('-d', '--dry-run', action="store_true", dest="dry_run", help="Don't modify anything on Github")
options, args = parser.parse_args()
if len(args) != 4:
parser.error('incorrect number of arguments')
google_project_name = args[0]
github_api_token = args[1]
github_user_name = args[2]
github_project = args[3]
google = gdata.projecthosting.client.ProjectHostingClient()
github = Github(username=github_user_name, api_token=github_api_token, requests_per_second=GITHUB_REQUESTS_PER_SECOND)
try:
process_issues()
except:
parser.print_help()
raise