Commits

Yuya Nishihara committed 4669477

ability to specify range of report id to import

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 \
-          project=kagemai_proj_id
+          project=kagemai_proj_id first=5
+
+Parameters:
+
+  RAILS_ENV: environment to import.
+  KAGEMAI_ROOT: path to kagemai root.
+  KAGEMAI_URL: [optional] used when linking to original Kagemai report.
+  project: id of original Kagemai project.
+  first: [optional] first report id to import.
+  last: [optional] next number of last report id to import.
 
 Copyright (c) 2009, Yuya Nishihara <yuya@tcha.org>
 
       TRACKER_BUG
     end
 
-    def self.import_project(kagemai_proj_id)
+    def self.import_project(kagemai_proj_id, first = nil, last = nil)
       raise 'kagemai project not specified' unless kagemai_proj_id
+      first = Integer(first) if first
+      last = Integer(last) if last
 
       puts "Importing reports: #{kagemai_proj_id}"
 
       switch_kcode(Kagemai::Config[:charset]) do
         kagemai_proj = @bts.open_project(kagemai_proj_id)
         kagemai_proj.each do |rep|
+          next if first and rep.id < first  # TODO: silly, but works
+          next if last and rep.id >= last   #
+
           issue = Issue.new(:subject => reformat_subject(kagemai_proj_id, rep),
                             :description => reformat_description(kagemai_proj_id, rep),
                             :created_on => rep.create_time)
 
   KagemaiImport.initialize()
   ActiveRecord::Base.transaction do
-    KagemaiImport.import_project(ENV['project'])
+    KagemaiImport.import_project(ENV['project'], ENV['first'], ENV['last'])
   end
 
 end