lib/pivotal_angel/project.rb in pivotal_angel-0.0.2 vs lib/pivotal_angel/project.rb in pivotal_angel-0.0.3

- old
+ new

@@ -1,32 +1,58 @@ module PivotalAngel class Project class << self def deep_clone(source_project, name) - new_project = source_project.clone - new_project.name = name - new_project.create + new_project = PivotalTracker::Project.new name: name, + iteration_length: source_project.iteration_length, + point_scale: source_project.point_scale - new_project = PivotalTracker::Project.all.detect { |document| document.name == new_project.name } + new_project = new_project.create puts "Copying stories from #{source_project.name} to #{new_project.name}" source_project.stories.all.each do |story| - new_story = story.clone - new_story.project_id = new_project.id - a_new_story = new_story.create + # new story will get the requested_by/owned_by of the api token owner + # to preserve users, you would need to clone the project first + # and add all users that were ever on the project to the + # new project first through the pivotal tracker website + description = "#{story.description}\n\nOriginally owned by #{story.owned_by}\nOriginally requested by #{story.requested_by}" + new_story = new_project.stories.create name: story.name, + description: description, + estimate: story.estimate, + story_type: story.story_type, + current_state: story.current_state, + accepted_at: story.accepted_at, + created_at: story.created_at, + labels: story.labels + + raise "Uh Oh: #{new_story.errors.join("\n")}" if new_story.errors.to_a.size > 0 + story.tasks.all.each do |task| - new_task = task.clone - new_task.story_id = a_new_story.id - new_task.project_id = new_project.id - new_task.create + new_task = nil + begin + new_task = new_story.tasks.create description: task.description, + complete: task.complete + putc "t" + rescue + puts "0"*80 + puts "unable to create #{new_task.inspect}" + puts "0"*80 + end end story.notes.all.each do |note| - new_note = note.clone - new_note.story_id = a_new_story.id - new_note.project_id = new_project.id - new_note.create + begin + new_story.notes.create text: "#{note.text}\n\nOriginally by #{note.author}", + noted_at: note.noted_at.to_s, + author: note.author + + putc "n" + rescue + puts "%"*80 + puts "unable to create #{note.inspect}" + puts "%"*80 + end end putc "." end puts "Done" new_project