Skip to content

Instantly share code, notes, and snippets.

@fairchild
Forked from codatory/pitoval_import.rake
Created February 17, 2011 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fairchild/831394 to your computer and use it in GitHub Desktop.
Save fairchild/831394 to your computer and use it in GitHub Desktop.
begin
require 'ruport'
rescue LoadError => err
warn "Couldn't load ruport gem: #{err}"
end
namespace :import do
desc 'Import tickets from CSV File'
task :csv => :environment do
csv_file = Table(Rails.root.join('db', 'seeds', 'import.csv'), :records => true)
csv_file.rename_columns({
'Story' => 'subject',
'Story Type' => 'story_type',
'Current State' => 'state',
'Description' => 'description',
'Estimate' => 'estimate'
})
csv_file.each do |row|
issue = Issue.new
story = row.to_hash
issue.project_id = 1
case story['story_type']
when 'chore'
issue.tracker_id = 4
when 'bug'
issue.tracker_id = 1
when 'feature'
issue.tracker_id = 2
else
issue.tracker_id = nil
end
issue.subject = story['subject']
issue.description = story['description']
issue.story_points = story['estimate']
issue.author = User.first
case story['state']
when 'unscheduled'
issue.status_id = 7
when 'unstarted'
issue.status_id = 1
when 'started'
issue.status_id = 2
when 'finished'
issue.done_ratio = 100
issue.status_id = 3
when 'accepted'
issue.status_id = 5
else
issue.status_id = 8
end
if issue.save
print '.'
else
print "! #{story.id} - #{issue.errors.first} !"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment