Permalink
Browse files

Save ALL the iterations

  • Loading branch information...
1 parent 9cacc5c commit 3ea7659bbcc43b1839d5957274233192354795b6 @iain committed Jan 21, 2012
View
No changes.
@@ -2,15 +2,15 @@ class PivotalTracker::Activity < ActiveRecord::Base
belongs_to :project, :class_name => "PivotalTracker::Project", :foreign_key => "pivotal_id"
- validates_presence_of :pivotal_id
+ validates_presence_of :pivotal_id, :project_id
def self.import(project, data)
activity = where(:pivotal_id => data[:id]).first || new(:pivotal_id => data[:id])
- activity.project_id = project.pivotal_id
- activity.event_type = data[:event_type]
- activity.occurred_at = data[:occurred_at]
- activity.author = data[:author]
- activity.description = data[:description]
+ activity.project_id = project.pivotal_id
+ activity.event_type = data[:event_type]
+ activity.occurred_at = data[:occurred_at]
+ activity.author = data[:author]
+ activity.description = data[:description]
activity.save!
end
@@ -3,15 +3,17 @@ class PivotalTracker::Iteration < ActiveRecord::Base
belongs_to :project, :class_name => "PivotalTracker::Project", :foreign_key => "pivotal_id"
validates_presence_of :pivotal_id
+ validates_presence_of :project_id
def self.import(project, data)
- iteration = where(:pivotal_id => data[:id]).first || new(:pivotal_id => data[:id])
- iteration.project_id = project.pivotal_id
- iteration.number = data[:number]
- iteration.start = data[:start]
- iteration.finish = data[:finish]
+ find_by = { :pivotal_id => data[:id], :project_id => project.pivotal_id }
+ iteration = where(find_by).first || new(find_by)
+ iteration.project_id = project.pivotal_id
+ iteration.number = data[:number]
+ iteration.start = data[:start]
+ iteration.finish = data[:finish]
iteration.team_strength = data[:team_strength]
- iteration.stories = data[:stories]
+ iteration.stories = data[:stories]
iteration.save!
end
@@ -10,17 +10,17 @@ class PivotalTracker::Project < ActiveRecord::Base
def self.import(data)
transaction do
project = where(:pivotal_id => data[:id]).first || new(:pivotal_id => data[:id])
- project.name = data[:name]
+ project.name = data[:name]
project.iteration_length = data[:iteration_length]
- project.week_start_day = data[:week_start_day]
- project.point_scale = data[:point_scale]
+ project.week_start_day = data[:week_start_day]
+ project.point_scale = data[:point_scale]
project.current_velocity = data[:current_velocity]
project.initial_velocity = data[:initial_velocity]
project.save!
- data[:iterations].each do |iteration|
+ Array(data[:iterations]).each do |iteration|
PivotalTracker::Iteration.import(project, iteration)
end
- data[:activities].each do |activity|
+ Array(data[:activities]).each do |activity|
PivotalTracker::Activity.import(project, activity)
end
end
@@ -53,9 +53,10 @@ def x(tag)
end
response.on_complete do
- puts "Got projects"
+ projects = Nokogiri::XML(response.body).search("//projects/project")
+ puts "Got #{projects.size} projects"
- Nokogiri::XML(response.body).search("//projects/project").each do |project|
+ projects.each do |project|
id = project.x("id")
puts "Reading project #{id} - #{project.x("name")}"
@@ -72,9 +73,10 @@ def x(tag)
res.on_complete do
- puts "Retrieved activities for project #{id}"
+ adoc = Nokogiri::XML(res.body).search("//activities/activity")
+ puts "Retrieved #{adoc.size} activities for project #{project.x("name")}"
- activities = Nokogiri::XML(res.body).search("//activities/activity").map do |activity|
+ activities = adoc.map do |activity|
{ :id => activity.x("id"),
:event_type => activity.x("event_type"),
@@ -87,9 +89,10 @@ def x(tag)
res2.on_complete do
- puts "Retrieved iterations for project #{id}"
+ idoc = Nokogiri::XML(res2.body).search("//iterations/iteration")
+ puts "Retrieved #{idoc.size} iterations for project #{project.x("name")}"
- iterations = Nokogiri::XML(res2.body).search("//iterations/iteration").map do |iteration|
+ iterations = idoc.map do |iteration|
{ :id => iteration.x("id"),
:number => iteration.x("number"),
:start => iteration.x("start"),

0 comments on commit 3ea7659

Please sign in to comment.