-
-
Save Pretz/589126 to your computer and use it in GitHub Desktop.
import trac tickets to github from a mysql trac install
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 MySQLdb | |
import urllib2 | |
import urllib | |
import simplejson | |
login = 'your github login' | |
token = 'your github API key' | |
repo = 'username/repo' | |
dbhost = 'your mysql hostname' | |
dbname = 'your mysql database name' | |
dbuser = 'your mysql login' | |
dbpass = 'your mysql password' | |
def urlopen(url, data): | |
try: | |
return urllib2.urlopen(url, urllib.urlencode(data)) | |
except urllib2.HTTPError, e: | |
return e | |
conn = MySQLdb.connect(host=dbhost, user=dbuser, passwd=dbpass, db=dbname, use_unicode=True, charset="utf8") | |
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