Commits

Yuya Nishihara  committed 9ae787d

ability to map internal <BTS:xxx> link to redmine #yyy

  • Participants
  • Parent commits 48e3cc6

Comments (0)

Files changed (1)

File lib/tasks/import_kagemai_reports.rake

       @iconv = Iconv.new($KCODE, Kagemai::Config[:charset])
     end
 
+    def self.reformat_text(kagemai_proj_id, report, text)
+      # map <BTS:n> link to #m
+      proj = map_project(kagemai_proj_id, report)
+      text.gsub(/<BTS:(\d+)>/) do |s|
+        e = Issue.find(:last, :conditions => ['project_id = ? AND subject LIKE ?',
+                                               proj.id, "#{SUBJECT_PREFIX % $1.to_i}%"], :order => 'id')
+        e ? "##{e.id}" : s
+      end
+    end
+
     def self.reformat_description(kagemai_proj_id, report)
-      if KAGEMAI_URL
-        link_url = "#{KAGEMAI_URL}?action=view_report&id=#{report.id}&project=#{kagemai_proj_id}"
-        "#{encode(report.first['body'])}\n\n#{link_url}"
-      else
-        encode(report.first['body'])
-      end
+      text = reformat_text(kagemai_proj_id, report, encode(report.first['body']))
+      return text unless KAGEMAI_URL
+
+      link_url = "#{KAGEMAI_URL}?action=view_report&id=#{report.id}&project=#{kagemai_proj_id}"
+      "#{text}\n\n#{link_url}"
     end
 
     def self.reformat_subject(kagemai_proj_id, report)
 
           rep.each do |msg|
             next if msg == rep.first  # first message is treated as issue
-            note = Journal.new(:notes => encode(msg['body']))
+            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