From d6a6d16c9cd012f1ad2d27cafdbfe0c0cfc2be9e Mon Sep 17 00:00:00 2001 From: Brien Wankel Date: Tue, 7 May 2013 14:00:01 -0700 Subject: [PATCH] Many changes and stuff --- .pryrc | 5 +++++ Gemfile | 2 +- Gemfile.lock | 24 +++++++++++++++--------- README.md | 2 +- trac2tracker.rb | 38 ++++++++++++++++++++++++-------------- 5 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 .pryrc diff --git a/.pryrc b/.pryrc new file mode 100644 index 0000000..1e8d382 --- /dev/null +++ b/.pryrc @@ -0,0 +1,5 @@ +Pry.commands.alias_command 'c', 'continue' +Pry.commands.alias_command 's', 'step' +Pry.commands.alias_command 'n', 'next' +Pry.commands.alias_command 'f', 'finish' +Pry.commands.alias_command 'exit', 'exit-program' diff --git a/Gemfile b/Gemfile index 51c8ce5..807e62c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'pivotal-tracker' +gem 'pivotal-tracker', :path => '~/dev/pivotal-tracker' gem 'sqlite3' gem 'ruby-progressbar' gem 'pry' diff --git a/Gemfile.lock b/Gemfile.lock index 85bfea7..6398542 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,17 @@ +PATH + remote: ~/dev/pivotal-tracker + specs: + pivotal-tracker (0.5.10) + builder + builder + crack + happymapper (>= 0.3.2) + nokogiri (>= 1.4.3) + nokogiri (>= 1.5.5) + nokogiri-happymapper (>= 0.5.4) + rest-client (~> 1.6.0) + rest-client (~> 1.6.0) + GEM remote: https://rubygems.org/ specs: @@ -19,14 +33,6 @@ GEM nokogiri (1.5.9) nokogiri-happymapper (0.5.7) nokogiri (~> 1.5) - pivotal-tracker (0.5.10) - builder - crack - happymapper (>= 0.3.2) - nokogiri (>= 1.4.3) - nokogiri (>= 1.5.5) - nokogiri-happymapper (>= 0.5.4) - rest-client (~> 1.6.0) pry (0.9.12.1) coderay (~> 1.0.5) method_source (~> 0.8) @@ -44,7 +50,7 @@ PLATFORMS ruby DEPENDENCIES - pivotal-tracker + pivotal-tracker! pry pry-debugger ruby-progressbar diff --git a/README.md b/README.md index 8ea4d40..0d5e640 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ trac2tracker ============ -A simple script to import a Trac sqlite database into a Pivotal Tracker project +A simple ruby script to import a Trac sqlite database into a Pivotal Tracker project diff --git a/trac2tracker.rb b/trac2tracker.rb index a64999b..cc72b94 100755 --- a/trac2tracker.rb +++ b/trac2tracker.rb @@ -11,7 +11,7 @@ pt_email = 'brien@reebosak.net' # pt_project_id = '784261' # CPF spt -pt_project_id = '820749' # CPF Test +pt_project_id = '821611' # CPF Test unless pt_email print "Pivotal Email: " @@ -46,9 +46,10 @@ memberships = (project.memberships.all).collect(&:name).map(&:downcase) # TODO: verify memberships - story = nil errors = 0 +error_ids = [] +comment_failures = [] ticket_progress = ProgressBar.create(:title => "Tickets: ", :format => "%t %c/%C (%p%) |%b>>%i|", :total => ticket_count.to_i) @@ -127,6 +128,8 @@ # bugs and releases can't have estimate estimate = nil if ['bug', 'release', 'chore'].include? story_type + # update progress bar with new ticket id + ticket_progress.title = "Ticket #{id}" begin story = project.stories.create( name: story, @@ -140,23 +143,30 @@ # owner: owner, description: description.chomp + "\n[trac#{id}] Imported from trac, original id #{id}" ) - rescue - puts $!.backtrace - puts "Ticket: #{id}" - binding.pry - end - # # migrate comments - # db.execute(query = 'select newvalue from ticket_change where field=="comment" and newvalue != \'\' and ticket=' + id.to_s + ' and newvalue !=' + id.to_s) do |comment| - # story.notes.create(:text => comment[0]) unless comment[0].empty? - # end + if story.errors.count > 0 puts "Failed on ticket #{id}" puts story.errors - binding.pry errors = errors + 1 + error_ids << id else - ticket_progress.title = "Ticket #{id}" + # migrate comments + begin + db.execute(query = 'select newvalue from ticket_change where field=="comment" and newvalue != \'\' and ticket=' + id.to_s + ' and newvalue !=' + id.to_s) do |comment| + story.notes.create(:text => comment[0]) unless comment[0].empty? + end + rescue + puts "failed adding comments to ticket #{id}" + comment_failures << id + end ticket_progress.increment end + rescue +# puts $!.backtrace + puts "Failed on ticket: #{id}" + end + end -puts "Errors: #{errors}" \ No newline at end of file +puts "\nErrors: #{errors}" if errors > 0 +puts "Ticket IDs: " + error_ids.join(',') if error_ids.length > 0 +puts "failed adding comments to: " + comment_failures.join(',') if comment_failures.length > 0 \ No newline at end of file