Created
July 29, 2010 07:53
-
-
Save dittos/497554 to your computer and use it in GitHub Desktop.
Trac tickets to GitHub issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys; reload(sys); sys.setdefaultencoding('utf-8') | |
import sqlite3 | |
import urllib2 | |
import urllib | |
import simplejson | |
login = 'your github id' | |
token = 'your github api key' | |
repo = 'username/reponame' | |
def urlopen(url, data): | |
try: | |
return urllib2.urlopen(url, urllib.urlencode(data)) | |
except urllib2.HTTPError, e: | |
return e | |
conn = sqlite3.connect('trac.db') | |
c = conn.cursor() | |
c.execute('SELECT id, summary, status, description FROM ticket') | |
for row in c: | |
id, summary, status, description = row | |
print 'Ticket #%d' % id | |
ticket = simplejson.load(urlopen('https://github.com/api/v2/json/issues/open/%s' % repo, {'login': login, 'token': token, 'title': summary, 'body': description})) | |
c2 = conn.cursor() | |
c2.execute('SELECT author, newvalue AS body FROM ticket_change WHERE field="comment" AND ticket=%d' % id) | |
for comment in c2: | |
print '- comment' | |
author, body = comment | |
urlopen('https://github.com/api/v2/json/issues/comment/%s/%d' % (repo, ticket['issue']['number']), {'login': login, 'token': token, 'comment': body + '\n\n--' + author}) | |
if status == 'closed': | |
print '- close' | |
urlopen('https://github.com/api/v2/json/issues/close/%s/%d' % (repo, ticket['issue']['number']), {'login': login, 'token': token}) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment