<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -22,4 +22,8 @@ namespace :app do
     require &quot;lib/burndown&quot;
     Burndown.new(File.dirname(__FILE__) + &quot;/config/config.yml&quot;)
   end
+  
+  task :update_milestones =&gt; :setup do
+    Burndown::Milestone.sync_with_lighthouse
+  end
 end
\ No newline at end of file</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -27,6 +27,12 @@ module Burndown
       get &quot;http://#{account}.#{lighthouse_host}/projects/#{remote_project_id}/milestones.xml&quot;, :headers =&gt; default_headers(token)
     end
     
+    def self.get_milestone_tickets(milestone_name, remote_project_id, account, token)
+      get &quot;http://#{account}.#{lighthouse_host}/projects/#{remote_project_id}/tickets.xml&quot;, :query =&gt; {
+        :q =&gt; &quot;milestone:'#{milestone_name}'&quot;
+      }, :headers =&gt; default_headers(token)
+    end
+    
     def self.create_callback(project_id, url, account, token)
       post &quot;http://#{account}.#{lighthouse_host}/callback_handlers.xml&quot;, :query =&gt; {:callback_handler =&gt;{
         :project_id =&gt; project_id,</diff>
      <filename>lib/burndown/lighthouse.rb</filename>
    </modified>
    <modified>
      <diff>@@ -22,5 +22,19 @@ module Burndown
       Time.now.utc.to_datetime
     end
     
+     # Queries the API for each milestone (yikes!). Hope you don't have too many.
+    def self.sync_with_lighthouse
+      Milestone.all.each do |milestone|
+        milestone.sync_with_lighthouse
+      end
+    end
+    
+    # Syncs up the milestone with lighthouse updates
+    def sync_with_lighthouse
+      results = Lighthouse.get_milestone_tickets(self.name, self.project.remote_id, self.project.token.account, self.project.token.token)
+      ticket_ids = results[&quot;tickets&quot;].collect{ |t| t[&quot;number&quot;] }.join(&quot;,&quot;)
+      self.milestone_events.create(:open_tickets =&gt; ticket_ids)
+    end
+    
   end
 end
\ No newline at end of file</diff>
      <filename>lib/burndown/milestone.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,12 +2,27 @@ module Burndown
   class MilestoneEvent
     include DataMapper::Resource
     
-    property :id,             Serial
-    property :who,            String
-    property :ticket_change,  Integer
-    property :created_at,     DateTime
+    property :id,               Serial
+    property :open_tickets,     Text,   :default =&gt; &quot;&quot; # comma-separated ids: 1,2,3
+    property :created_on,       Date
     
     belongs_to :milestone
     
+    def prev_record
+      @@prev_record ||= (self.class.first(:created_on.lt =&gt; self.created_on) || MilestoneEvent.new)
+    end
+    
+    def tickets_opened
+      @@tickets_opened ||= (self.open_tickets.split - prev_record.open_tickets.split).size
+    end
+    
+    def tickets_closed
+      @@tickets_closed ||= (prev_record.open_tickets.split - self.open_tickets.split).size
+    end
+    
+    def ticket_change
+      tickets_opened - tickets_closed
+    end
+    
   end
 end
\ No newline at end of file</diff>
      <filename>lib/burndown/milestone_event.rb</filename>
    </modified>
    <modified>
      <diff>@@ -39,7 +39,7 @@ module Burndown
       result = Lighthouse.get_milestones(self.remote_id, self.token.account, self.token.token)
       (result[&quot;milestones&quot;] || []).each do |milestone|
         m = self.milestones.create(:name =&gt; milestone[&quot;title&quot;], :remote_id =&gt; milestone[&quot;id&quot;], :activated_at =&gt; Time.now.utc)
-        m.milestone_events.create(:who =&gt; &quot;[pre-existing]&quot;, :ticket_change =&gt; milestone[&quot;open_tickets_count&quot;])
+        m.sync_with_lighthouse
       end
     end
     </diff>
      <filename>lib/burndown/project.rb</filename>
    </modified>
    <modified>
      <diff>@@ -28,7 +28,7 @@
     &lt;h3&gt;&lt;%= event.created_at.strftime(&quot;%B %e&quot;) %&gt;&lt;/h3&gt;
     &lt;span class=&quot;big&quot;&gt;&lt;%= &quot;+&quot; if event.ticket_change &gt; 0 %&gt;&lt;%= event.ticket_change %&gt;&lt;/span&gt;
     &lt;ul class=&quot;events&quot;&gt;
-      &lt;li&gt;&lt;%=h event.who %&gt; &lt;strong&gt;&lt;%= event.ticket_change &gt; 0 ? &quot;opened&quot; : &quot;closed&quot; %&gt;&lt;/strong&gt; &lt;em class=&quot;&lt;%= event.ticket_change &gt; 0 ? &quot;positive&quot; : &quot;negative&quot; %&gt;&quot;&gt;&lt;%= event.ticket_change %&gt;&lt;/em&gt; tickets&lt;/li&gt;
+      &lt;li&gt;&lt;strong&gt;&lt;%= event.ticket_change &gt; 0 ? &quot;Opened&quot; : &quot;Closed&quot; %&gt;&lt;/strong&gt; &lt;em class=&quot;&lt;%= event.ticket_change &gt; 0 ? &quot;positive&quot; : &quot;negative&quot; %&gt;&quot;&gt;&lt;%= event.ticket_change %&gt;&lt;/em&gt; tickets&lt;/li&gt;
     &lt;/ul&gt;
   &lt;/li&gt;
   &lt;% end %&gt;</diff>
      <filename>views/timeline.erb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cbbb6cb0b27195d24a8a046efeb9c58c0a7e5537</id>
    </parent>
  </parents>
  <author>
    <name>Kyle Neath</name>
    <email>kneath@gmail.com</email>
  </author>
  <url>http://github.com/kneath/lighthouse_burndown/commit/3c27f9a8565493699a17b7204ef6a32856e90ff6</url>
  <id>3c27f9a8565493699a17b7204ef6a32856e90ff6</id>
  <committed-date>2009-05-01T02:16:33-07:00</committed-date>
  <authored-date>2009-05-01T02:16:33-07:00</authored-date>
  <message>Retrieve a list of open ticket numbers for a milestone</message>
  <tree>34b2da31bacd9171c4c2dc3b9321061eac2245cd</tree>
  <committer>
    <name>Kyle Neath</name>
    <email>kneath@gmail.com</email>
  </committer>
</commit>
