Commits

Yuya Nishihara committed 85577b9

added handling of attachment files

  • Participants
  • Parent commits 9ae787d

Comments (0)

Files changed (1)

lib/tasks/import_kagemai_reports.rake

           issue.priority = map_priority(kagemai_proj_id, rep)
           issue.assigned_to = map_assigned_to(kagemai_proj_id, rep)
           issue.done_ratio = map_done_ratio(kagemai_proj_id, rep)
-          # TODO: attachment
 
           Time.fake(rep.modify_time) { issue.save }
           print "[#{rep.id}->#{issue.id}]"
 
           rep.each do |msg|
-            next if msg == rep.first  # first message is treated as issue
+            if msg.has_element? 'attachment'
+              msg.element('attachment').each do |e|
+                class << e
+                  attr_accessor :file
+                  def original_filename; name; end
+                  def content_type; mime_type; end
+                  def read(*args); @file.read(*args); end
+                end
+                e.file = kagemai_proj.open_attachment(e.seq)
+                att = Attachment.new
+                att.file = e
+                att.author = map_author(kagemai_proj_id, msg)
+                att.container = issue
+                Time.fake(e.create_time) { att.save }
+              end
+            end
+
+            next if msg == rep.first  # first message is treated as issue except for attachment
             note = Journal.new(:notes => reformat_text(kagemai_proj_id, msg, encode(msg['body'])))
             note.journalized = issue
             note.user = map_author(kagemai_proj_id, msg)
-            # TODO: attachment
             Time.fake(msg.create_time) { note.save }
             print '.'
           end