Created
December 27, 2011 15:23
-
-
Save rtekie/1523987 to your computer and use it in GitHub Desktop.
Migrate tickets from a Trac database to LighthouseApp
This file contains hidden or 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
# Migrate records from a Trac database to LighthouseApp | |
require 'rubygems' | |
require 'sqlite3' | |
require 'lib/lighthouse.rb' # download from https://github.com/Caged/lighthouse-api | |
# Connect to Lighthouse API | |
Lighthouse.account = 'YOUR LIGHTHOUSE ACCOUNT' | |
Lighthouse.token = 'YOUR LIGHTHOUSE API TOKEN' | |
project = Lighthouse::Project.find(:all).first | |
puts "MIGRATING TICKETS TO PROJECT: #{project.name}" | |
# Connect to database | |
db = SQLite3::Database.new("trac.db") | |
# Retrieve open trac ticket records | |
columns, *rows = db.execute2("select * from ticket t where t.status in ('new', 'assigned') order by t.id") | |
puts "TICKET TABLE COLUMNS" | |
(0..columns.length-1).each do |i| | |
puts "#{i}:#{columns[i]}" | |
end | |
# Process ticket records | |
rows.each do |row| | |
puts row[0] # trac ticket ID | |
# Create a new Lighthouse ticket | |
ticket = Lighthouse::Ticket.new(:project_id => project.id) | |
ticket.title = row[14] # summary column | |
ticket.body = row[15] # description column | |
# Additional data mapings go here | |
# Get trac ticket changes and append to the Lighthouse ticket | |
col, *updates = db.execute2("select newvalue from ticket_change where ticket=? and field = 'comment'", row[0]) | |
updates.each do |update| | |
upd = update[0] | |
ticket.body << "\n" + upd if !upd.empty? | |
end | |
# Display progress | |
puts ticket.title | |
puts ticket.body | |
ticket.save | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment