Commits

Yuya Nishihara committed 590db2d

added PROJECT_MAP, mapping of kagemai project id to redmine project identifier

Comments (0)

Files changed (1)

lib/tasks/import_kagemai_reports.rake

 
   $ rake redmine:import_kagemai_reports RAILS_ENV=production \
           KAGEMAI_ROOT=/path/to/kagemai KAGEMAI_URL=http://example.org/kagemai/guest.cgi \
-          kagemai_project=src_proj_id redmine_project=dest_proj_id
+          project=kagemai_proj_id
 
 Copyright (c) 2009, Yuya Nishihara <yuya@tcha.org>
 
     TRACKER_SUPPORT = Tracker.find_by_position(3)
 
     # Kagemai to Redmine
+    PROJECT_MAP = {}
     STATUS_MAP = {'受付済' => '担当', '割当済み' => '担当', '修正済' => '解決', '確認待ち' => '解決',
                   '保留' => '新規', '完了' => '終了'}
     DONE_RATIO_MAP = {'修正済' => 100, '確認待ち' => 100, '完了' => 100}  # default: 0
       "[Kagemai:#{'%03d' % report.id}] #{encode(report.attr('title'))}"
     end
 
+    def self.map_project(kagemai_proj_id, report)
+      Project.find_by_identifier(PROJECT_MAP[kagemai_proj_id] || kagemai_proj_id) \
+          or raise "unknown project: #{kagemai_proj_id}"
+    end
+
     def self.map_status(report)
       status = encode(report['status'])
       IssueStatus.find_by_name(STATUS_MAP[status] || status) or raise "unknown status: #{status}"
       TRACKER_BUG
     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
+    def self.import_project(kagemai_proj_id)
+      raise 'kagemai project not specified' unless kagemai_proj_id
 
-      puts "Importing reports: kagemai:#{kagemai_proj_id} -> redmine:#{redmine_proj_id}"
-      redmine_proj = Project.find_by_identifier(redmine_proj_id) or raise "unknown redmine project: #{redmine_proj_id}"
+      puts "Importing reports: #{kagemai_proj_id}"
 
       # XMLScan cannot parse reports correctly with $KCODE = 'UTF-8'
       switch_kcode(Kagemai::Config[:charset]) do
         kagemai_proj.each do |rep|
           issue = Issue.new(:subject => reformat_subject(rep), :description => reformat_description(kagemai_proj_id, rep),
                             :created_on => rep.create_time)
-          issue.project = redmine_proj
+          issue.project = map_project(kagemai_proj_id, rep)
           issue.author = map_author(rep)
           issue.tracker = map_tracker(rep)
           issue.status = map_status(rep)
   end
 
   KagemaiImport.initialize()
-  KagemaiImport.import_project(ENV['redmine_project'], ENV['kagemai_project'])
+  KagemaiImport.import_project(ENV['project'])
 
 end
 end