Skip to content

Instantly share code, notes, and snippets.

@craigds
Created September 12, 2010 06:26
Show Gist options
  • Save craigds/575900 to your computer and use it in GitHub Desktop.
Save craigds/575900 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from datetime import datetime
import os
import sys
import gdata.projecthosting.client
import gdata.projecthosting.data
import gdata.gauth
import gdata.client
import gdata.data
def getid(issue):
return issue.id.text.rsplit('/', 1)[-1]
user_map = {
# GC username : GH username
'batiste.bieler' : 'batiste',
'brosner' : 'brosner',
'matthias.kestenholz' : 'matthiask',
'mocksoul' : 'mocksoul',
'craig.ds' : 'craigds',
'jonathan.buchanan' : 'insin',
}
label_map = {
'Milestone-Release0.4': 'Milestone-0.4',
'Milestone-Release0.5': 'Milestone-0.5',
'Type-Enhancement': 'Type-Enhancement',
'Type-Defect': 'Type-Defect',
'Type-Task': 'Type-Task',
}
def main():
from github2.client import Github
github = Github(username=os.environ['GITHUB_USERNAME'], api_token=os.environ['GITHUB_API_TOKEN'])
gc_project = sys.argv[1]
gh_project = sys.argv[2]
client = gdata.projecthosting.client.ProjectHostingClient()
query = gdata.projecthosting.client.Query(max_results=500)
feed = client.get_issues(gc_project, query=query)
for issue in feed.entry:
issue_id = getid(issue)
print "%s %s %s\n%s" % (issue_id, issue.state.text, issue.title.text, issue.content.text)
### create the Github issue
gh_issue = github.issues.open(
gh_project,
title=issue.title.text,
body="Originally [GC %s](http://code.google.com/p/django-mptt/issues/detail?id=%s)\n\n%s" % (issue_id, issue_id, issue.content.text)
)
### add mapped labels
gh_labels = set(['from-googlecode'])
for label in issue.label:
if label.text in label_map:
gh_labels.add(label_map[label.text])
print "LABELS:", ", ".join(sorted(list(gh_labels)))
for label in gh_labels:
github.issues.add_label(gh_project, issue_id, label)
### migrate comments
comments_feed = client.get_comments(gc_project, issue_id)
for comment in comments_feed.entry:
comment_text = comment.content.text
author = comment.author[0]
if comment_text:
date = datetime.strptime(comment.published.text.split('T')[0], '%Y-%m-%d').date().strftime('%d %b %y')
print " %s, %s:" % (author.name.text, date)
print "\n " + "\n ".join(comment_text.split("\n"))
author_name = author.name.text
author_url = 'http://code.google.com%s' % author.uri.text
if author_name in user_map:
author_name = user_map[author_name]
author_url = 'http://github.com/%s' % author_name
author_markdown = '[%s](%s)' % (author_name, author_url)
comment_content = "%s (%s):\n\n%s" % (author_markdown, date, comment_text.strip())
# FIXME : this doesn't seem to work! It posts the right stuff, and
# gets back a valid response, but no comment gets created!
github.issues.comment(gh_project, issue_id, comment_content)
### close issue if necessary
if issue.state.text == 'closed':
github.issues.close(gh_project, gh_issue.number)
#TODO remove this once it all works :)
break
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment