Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import trac tickets to github from a mysql trac install
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
You can’t perform that action at this time.