diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-04-21 12:32:00 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-04-21 12:32:00 +0000 |
commit | 86dfdc36bd5f63f5ac4197c0e1e0e422555818fd (patch) | |
tree | e0970d8fa7b4b46506ac2ac999ab5d89d35779a6 /lib | |
parent | eca214a671fcbe0a30a643bcaf4691fd7130f6a9 (diff) | |
parent | 0c650dc0e2d030b6cfd39bbe25f88c5e349f5c70 (diff) | |
download | gitlab-ce-86dfdc36bd5f63f5ac4197c0e1e0e422555818fd.tar.gz |
Merge branch 'google-code-fixes' into 'master'
Fix some issues with Google Code importer
Thanks, @mrtux, for reporting all of these.
See merge request !551
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/google_code_import/importer.rb | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/lib/gitlab/google_code_import/importer.rb b/lib/gitlab/google_code_import/importer.rb index b5e82563ff1..70bfe059776 100644 --- a/lib/gitlab/google_code_import/importer.rb +++ b/lib/gitlab/google_code_import/importer.rb @@ -30,7 +30,10 @@ module Gitlab def user_map @user_map ||= begin - user_map = Hash.new { |hash, user| Client.mask_email(user) } + user_map = Hash.new do |hash, user| + # Replace ... by \.\.\., so `johnsm...@gmail.com` isn't autolinked. + Client.mask_email(user).sub("...", "\\.\\.\\.") + end import_data = project.import_data.try(:data) stored_user_map = import_data["user_map"] if import_data @@ -203,25 +206,25 @@ module Gitlab end def linkify_issues(s) - s.gsub(/([Ii]ssue) ([0-9]+)/, '\1 #\2') + s = s.gsub(/([Ii]ssue) ([0-9]+)/, '\1 #\2') + s = s.gsub(/([Cc]omment) #([0-9]+)/, '\1 \2') + s end def escape_for_markdown(s) - s = s.gsub("*", "\\*") - s = s.gsub("#", "\\#") + # No headings and lists + s = s.gsub(/^#/, "\\#") + s = s.gsub(/^-/, "\\-") + + # No inline code s = s.gsub("`", "\\`") - s = s.gsub(":", "\\:") - s = s.gsub("-", "\\-") - s = s.gsub("+", "\\+") - s = s.gsub("_", "\\_") - s = s.gsub("(", "\\(") - s = s.gsub(")", "\\)") - s = s.gsub("[", "\\[") - s = s.gsub("]", "\\]") - s = s.gsub("<", "\\<") - s = s.gsub(">", "\\>") + + # Carriage returns make me sad s = s.gsub("\r", "") + + # Markdown ignores single newlines, but we need them as <br />. s = s.gsub("\n", " \n") + s end @@ -276,11 +279,18 @@ module Gitlab if raw_updates.has_key?("blockedOn") blocked_ons = raw_updates["blockedOn"].map do |raw_blocked_on| name, id = raw_blocked_on.split(":", 2) - if name == project.import_source - "##{id}" - else - "#{project.namespace.path}/#{name}##{id}" - end + + deleted = name.start_with?("-") + name = name[1..-1] if deleted + + text = + if name == project.import_source + "##{id}" + else + "#{project.namespace.path}/#{name}##{id}" + end + text = "~~#{text}~~" if deleted + text end updates << "*Blocked on: #{blocked_ons.join(", ")}*" end @@ -288,11 +298,18 @@ module Gitlab if raw_updates.has_key?("blocking") blockings = raw_updates["blocking"].map do |raw_blocked_on| name, id = raw_blocked_on.split(":", 2) - if name == project.import_source - "##{id}" - else - "#{project.namespace.path}/#{name}##{id}" - end + + deleted = name.start_with?("-") + name = name[1..-1] if deleted + + text = + if name == project.import_source + "##{id}" + else + "#{project.namespace.path}/#{name}##{id}" + end + text = "~~#{text}~~" if deleted + text end updates << "*Blocking: #{blockings.join(", ")}*" end @@ -340,7 +357,7 @@ module Gitlab def format_issue_body(author, date, content, attachments) body = [] - body << "*By #{author} on #{date}*" + body << "*By #{author} on #{date} (imported from Google Code)*" body << "---" if content.blank? |