Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pivotal Tracker Importer for Redmine
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
@thebeline

This comment has been minimized.

Copy link

@thebeline thebeline commented Apr 29, 2013

How does this work? I would like to use this, but am fairly new to ruby... Hence, I don't get the 'gist' of this.... :-D

Quick explanation please? Thanks.

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.