Created
June 11, 2009 19:48
-
-
Save BDQ/128182 to your computer and use it in GitHub Desktop.
lightmine.rake
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
namespace :lightmine do | |
task :export => :environment do | |
project = Project.find_by_name('Spree', :include => {:issues => [:fixed_version, :author]}) | |
versions = [] | |
project.versions.each do |version| | |
version_export = {} | |
version_export.merge! version.attributes.delete_if { |k,v| !%w{id name description}.include? k} | |
versions << version_export | |
end | |
File.open("#{RAILS_ROOT}/versions.yml", 'w' ) do |file| | |
YAML.dump( versions , file) | |
end | |
issues = [] | |
project.issues.each do |issue| | |
issue_export = {} | |
issue_export.merge! issue.attributes.delete_if { |k,v| !%w{id subject description created_on}.include? k} | |
issue_export['fixed_version_name'] = issue.fixed_version.nil? ? '' : issue.fixed_version.name | |
issue_export['status'] = issue.status.name.downcase | |
issue_export.merge! issue.author.attributes.delete_if { |k,v| !%w{lastname firstname mail}.include? k} | |
issue_export['journals'] = [] | |
issue.journals.each do |journal| | |
next if journal.notes == "" | |
journal_export = {} | |
journal_export.merge! journal.attributes.delete_if { |k,v| !%w{notes created_on}.include? k} | |
journal_export.merge! journal.user.attributes.delete_if { |k,v| !%w{lastname firstname}.include? k} | |
issue_export['journals'] << journal_export | |
end | |
issues << issue_export | |
end | |
File.open("#{RAILS_ROOT}/issues.yml", 'w' ) do |file| | |
YAML.dump( issues , file) | |
end | |
end | |
task :import => :environment do | |
require "lighthouse" | |
Lighthouse.account = 'bdq-spree' | |
Lighthouse.token = '2fa1d14d3a017b103c85c6323d35e5d905f51c4c' | |
project_id = 30729 | |
project = Lighthouse::Project.find(project_id) | |
# Migrate from Redmin Version to Lighthouse Milestones | |
versions = YAML::load( File.open( "#{RAILS_ROOT}/versions.yml" ) ) | |
versions.each do |version| | |
if project.milestones.find{ |m| m.title == version['name']}.nil? | |
milestone = Lighthouse::Milestone.new(:project_id => project_id) | |
milestone.title = version['name'] | |
milestone.save | |
end | |
end | |
#reload all milestones | |
all_milestones = project.milestones | |
# Migrate from Redmin Issues to Lighthouse Tickets | |
issues = YAML::load( File.open( "#{RAILS_ROOT}/issues.yml" ) ) | |
#temporarily add blank tickets with id's to the highest ticket number | |
max_number = issues.sort_by {|issue| issue['id']}.last['id'].to_i | |
puts max_number | |
i = 0 | |
max_number.times do | |
ticket = Lighthouse::Ticket.new(:project_id => project_id) | |
ticket.title = '.' | |
ticket.save | |
puts i += 1 | |
end | |
issues.each do |issue| | |
milestone = all_milestones.find{ |m| m.title == issue['fixed_version_name']} | |
ticket = Lighthouse::Ticket.find(issue['id'].to_i, :params => { :project_id => project_id }) | |
ticket.title = issue['subject'] | |
ticket.body = "[Originally reported by: #{issue['firstname']} #{issue['lastname']}] | |
#{issue['description']}" | |
ticket.state = issue['status'] | |
ticket.created_at = issue['created_on'] | |
ticket.updated_at = issue['updated_on'] | |
ticket.milestone_id = milestone.id unless milestone.nil? | |
ticket.save | |
end | |
end | |
task :killtickets => :environment do | |
require "lighthouse" | |
Lighthouse.account = 'bdq-spree' | |
Lighthouse.token = '2fa1d14d3a017b103c85c6323d35e5d905f51c4c' | |
project_id = 30729 | |
project = Lighthouse::Project.find(project_id) | |
all_tickets = project.tickets | |
while all_tickets.length > 0 | |
all_tickets.each { |ticket| ticket.destroy } | |
all_tickets = project.tickets | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment