Adds Trac ticket updating
M .ditz/issue-3455abd67e78f997c74d72aff184585b74083415.yaml +6 -2
@@ 3,7 3,7 @@ title: Add ability to change title
 desc: ""
 type: :task
 component: trac to ditz
-release: 
+release: "2010.2"
 reporter: Sean Russell <ser@ser1.net>
 status: :unstarted
 disposition: 

          
@@ 16,4 16,8 @@ log_events:
   - Sean Russell <ser@ser1.net>
   - created
   - ""
-trac_id: 
+- - 2010-01-28 01:50:47.550377 Z
+  - Sean Russell <ser@ser1.net>
+  - assigned to release 2010.2 from unassigned
+  - ""
+trac_id: 3

          
M .ditz/issue-4d26d5a4a0a8500f1b24d28a954c3624be95097f.yaml +10 -2
@@ 3,7 3,7 @@ title: Add debug mode
 desc: ""
 type: :task
 component: ditz-trac
-release: 
+release: "2010.1"
 reporter: Sean Russell <ser@ser1.net>
 status: :unstarted
 disposition: 

          
@@ 16,4 16,12 @@ log_events:
   - Sean Russell <ser@ser1.net>
   - created
   - ""
-trac_id: 
+- - 2010-01-28 01:49:48.022362 Z
+  - Sean Russell <ser@ser1.net>
+  - commented
+  - Add a -d option, and turn off the logging messages
+- - 2010-01-28 01:50:36.310381 Z
+  - Sean Russell <ser@ser1.net>
+  - assigned to release 2010.1 from unassigned
+  - ""
+trac_id: 1

          
M .ditz/issue-7999b8b298dd44690f44349da9a8dd88bbe4d9a3.yaml +1 -1
@@ 28,4 28,4 @@ log_events:
   - Sean Russell <ser@ser1.net>
   - closed with disposition fixed
   - ""
-trac_id: 
+trac_id: 4

          
M .ditz/issue-837b4acc500d7835adfecfc75b948d57b6e2337e.yaml +1 -1
@@ 22,4 22,4 @@ log_events:
   - |-
     Duh.  Ditz already supports this -- put the .ditz-config in the project
     directory, and it overrides the global one.
-trac_id: 
+trac_id: 6

          
M .ditz/issue-8f7f150d0c575b55bd15bbb5bba4b7285ff7e942.yaml +1 -1
@@ 18,4 18,4 @@ log_events:
   - Sean Russell <ser@ser1.net>
   - created
   - ""
-trac_id: 
+trac_id: 5

          
M .ditz/issue-9618638bbe9059ffa431f5edc8d7b9c9a938dbab.yaml +1 -1
@@ 16,4 16,4 @@ log_events:
   - Sean Russell <ser@ser1.net>
   - created
   - ""
-trac_id: 
+trac_id: 7

          
M .ditz/issue-b6c0977924baa85b69eae1737c281ad03ce211af.yaml +1 -1
@@ 16,4 16,4 @@ log_events:
   - Sean Russell <ser@ser1.net>
   - created
   - ""
-trac_id: 
+trac_id: 2

          
M .ditz/project.yaml +9 -0
@@ 18,3 18,12 @@ releases:
     - Sean Russell <ser@ser1.net>
     - created
     - ""
+- !ditz.rubyforge.org,2008-03-06/release 
+  name: "2010.2"
+  status: :unreleased
+  release_time: 
+  log_events: 
+  - - 2010-01-28 01:50:24.274350 Z
+    - Sean Russell <ser@ser1.net>
+    - created
+    - ""

          
M trac-sync.rb +44 -2
@@ 156,6 156,9 @@ EOS
       new_tickets
     end
     
+    # Creates Trac components for all of the ditz components that are missing
+    # in Trac
+    # trac: the trac4r object to create the components in
     def maybe_create_components( trac )
       components = trac.query("ticket.component.getAll")
       @project.components.each do |component|

          
@@ 164,6 167,9 @@ EOS
       end
     end
 
+    # Creates Trac milestones for all of the ditz releases that are missing in
+    # Trac
+    # trac: the trac4r object to create the milestones in
     def maybe_create_milestones( trac )
       milestones = trac.query("ticket.milestone.getAll")
       @project.releases.each do |release|

          
@@ 226,6 232,8 @@ EOS
       nil
     end
 
+    # Creates a ditz release, IFF it doesn't exist
+    # milestone: the String name of the release to create
     def maybe_create_release( milestone )
         release = @project.releases.find { |r| r.name == milestone }
         unless release 

          
@@ 235,6 243,8 @@ EOS
         end
     end
 
+    # Creates a ditz component, IFF it doesn't already exist
+    # comp: the String name of the component to create
     def maybe_create_component( comp )
         component = @project.components.find { |r| r.name == comp }
         unless component 

          
@@ 255,7 265,38 @@ EOS
     end
 
 
+    # TODO this need beaucoup more error checking
     def update_tickets( pairs, trac )
+      pairs.each do |ticket, issue|
+        puts "Working on #{ticket.id}/#{issue.id[0,4]}"
+        ticket_last_updated = ticket.updated_at.to_time
+        issue.log_events.each do |event|
+          if event[0] > ticket_last_updated
+            attrs = {}
+            case event[2]
+            when "created"
+              # This should have been done by create_tickets
+              # How did we get here, anyway?
+              STDERR.puts( "This is strange.  Sean could have sworn that you'd never get here." )
+              STDERR.puts( "It indicates that there's something wrong with the time stamps." )
+              raise "Suspicious 'create' event encountered, which could mess up the ticket, so aborting."
+            when /^assigned to release (.*?) from .*/
+              attrs[ "milestone" ] = $1
+            when /^changed status from \w to (.*)$/
+              attrs[ "milestone" ] = newstat
+            when "commented"
+              # NOOP.  The comment is event[3]
+            when /^closed with disposition (.*)$/
+              attrs[ "resolution" ] = DISPO_RES[ issue.disposition ]
+              attrs[ "status" ] = DSTATUS_TSTATUS[ issue.status ]
+            else
+              raise "Found unknown event #{event[2]}!  Aborting. Needs code fix."
+            end
+            puts "Updating ticket #{ticket.id} with #{attrs.inspect} and comment #{event[3].inspect}"
+            trac.query( "ticket.update", ticket.id, event[3], attrs )
+          end
+        end
+      end
     end
 
 

          
@@ 293,7 334,6 @@ EOS
               when "owner"
                 whats << change_status( :in_progress, issue )
               when "resolution"
-                RES_DISPO
                 issue.disposition = RES_DISPO[ new_change[4] ]
               when "status"
                 whats << change_status( TSTATUS_DSTATUS[ new_change[4] ], issue )

          
@@ 314,7 354,9 @@ EOS
               end
             end
             # All changes were at the same time, and therefore by the same person
-            issue.log_at( time, whats.join(", "), array_of_changes[0][1], comment )
+            whats.each do |what|
+              issue.log_at( time, what, array_of_changes[0][1], comment )
+            end
           end
         end
       end