Commits

Yuya Nishihara committed 8b8d7e1

ability to map assigned to user

Comments (0)

Files changed (1)

lib/tasks/import_kagemai_reports.rake

     PRIORITY_MAP = {'緊急' => '急いで', '高' => '高め', '中' => '通常', '低' => '低め'}
     USER_EMAIL_MAP = {}
 
+    # assigned user name to email
+    USER_NAME_EMAIL_MAP = {'未定' => nil}
+
     def self.initialize()
       # we cannot add LOAD_PATH before loading rails due to unexpected
       # `uninitialized constant XMLScan::Visitor' error.
       User.find_by_mail(USER_EMAIL_MAP[name] || name) or raise "unknown user: #{name}"
     end
 
+    def self.map_assigned_to(report)
+      name = encode(report['assigned'])
+      email = USER_NAME_EMAIL_MAP.fetch(name, name)
+      return nil unless email  # nil means not assigned
+      User.find_by_mail(email) or raise "unknown user: #{name} (email: #{email})"
+    end
+
     def self.import_project(redmine_proj_id, kagemai_proj_id)
       raise 'redmine_project not specified' unless redmine_proj_id
       raise 'kagemai_project not specified' unless kagemai_proj_id
           issue.tracker = TRACKER_BUG  # FIXME
           issue.status = map_status(rep)
           issue.priority = map_priority(rep)
+          issue.assigned_to = map_assigned_to(rep)
           # TODO: attachment
 
           Time.fake(rep.modify_time) { issue.save }