Skip to content

Commit

Permalink
Comment and author history is now imported by appending to the story …
Browse files Browse the repository at this point in the history
…description
  • Loading branch information
Brien Wankel committed May 8, 2013
1 parent 6db5d76 commit c4a2e69
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
26 changes: 10 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
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:
Expand All @@ -29,10 +15,18 @@ GEM
libxml-ruby (~> 2.0)
libxml-ruby (2.6.0)
method_source (0.8.1)
mime-types (1.22)
mime-types (1.23)
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)
Expand All @@ -50,7 +44,7 @@ PLATFORMS
ruby

DEPENDENCIES
pivotal-tracker!
pivotal-tracker
pry
pry-debugger
ruby-progressbar
Expand Down
41 changes: 26 additions & 15 deletions trac2tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,29 @@
puts 'You do not appear to have permission to manage this project'
end

db = SQLite3::Database.new(trac_db)
puts 'Trac db loaded'

ticket_count = db.get_first_value('select count(*) from ticket')


usernames = []
memberships = (project.memberships.all).collect(&:name).map(&:downcase)
# TODO: verify memberships
memberships.each do |member|
(first, last) = member.split
usernames << first[0].downcase + last.downcase
end

story = nil
errors = 0
error_ids = []
comment_failures = []
columns = nil

db = SQLite3::Database.new(trac_db)
puts 'Trac db loaded'

ticket_count = db.get_first_value('select count(*) from ticket')
ticket_progress = ProgressBar.create(:title => 'Tickets: ',
:format => '%t %c/%C (%p%) |%b>>%i|', :total => ticket_count.to_i)

columns = nil

db.execute2('select * from ticket order by id desc') do |row_array|

if columns.nil?
Expand Down Expand Up @@ -109,13 +114,28 @@
# project.memberships.create(name: requested_by)
memberships << requested_by.downcase
end

accepted_at = Time.at(row[:changetime]) if row[:status] == 'accepted'
# bugs and releases can't have estimate
estimate = nil if %w(bug release chore).include? story_type

# update progress bar with new ticket id
ticket_progress.title = "Ticket #{id}"

# migrate comments
# Pivotal API does not allow setting author when creating a note, so
# we place the imported comment history into the description
begin
db.execute(query = 'select author, newvalue from ticket_change where field=="comment" and newvalue != \'\' and ticket=' + id.to_s + ' and newvalue !=' + id.to_s) do |comment|
description = description + "\n\ncomment from #{comment[0]}:\n#{comment[1]}" unless comment[1].empty?
end
rescue
puts "failed adding comments to ticket #{id}"
comment_failures << id
end
begin


story = project.stories.create(
name: story,
labels: labels,
Expand All @@ -135,15 +155,6 @@
errors = errors + 1
error_ids << id
else
# 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
Expand Down

0 comments on commit c4a2e69

Please sign in to comment.