Commit 86dfdc36 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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
parents eca214a6 0c650dc0
...@@ -68,7 +68,7 @@ class Import::GoogleCodeController < Import::BaseController ...@@ -68,7 +68,7 @@ class Import::GoogleCodeController < Import::BaseController
def status def status
unless client.valid? unless client.valid?
return redirect_to new_import_google_path return redirect_to new_import_google_code_path
end end
@repos = client.repos @repos = client.repos
......
...@@ -8,9 +8,31 @@ ...@@ -8,9 +8,31 @@
Customize how Google Code email addresses and usernames are imported into GitLab. Customize how Google Code email addresses and usernames are imported into GitLab.
In the next step, you'll be able to select the projects you want to import. In the next step, you'll be able to select the projects you want to import.
%p %p
The user map is a JSON document mapping Google Code users (as keys) to the way they will be imported into GitLab (as values). By default the username is masked to ensure users' privacy. The user map is a JSON document mapping the Google Code users that participated on your projects to the way their email addresses and usernames will be imported into GitLab. You can change this by changing the value on the right hand side of <code>:</code>. Be sure to preserve the surrounding double quotes, other punctuation and the email address or username on the left hand side.
%ul
%li
%strong Default: Directly import the Google Code email address or username
%p %p
To map a Google Code user to a full name or GitLab user, simply replace the value, e.g. <code>"johnsmith@gmail.com": "John Smith"</code> or <code>"johnsmith@gmail.com": "@johnsmith"</code>. Be sure to preserve the surrounding double quotes and other punctuation. <code>"johnsmith@example.com": "johnsm...@example.com"</code>
will add "By johnsm...@example.com" to all issues and comments originally created by johnsmith@example.com.
The email address or username is masked to ensure the user's privacy.
%li
%strong Map a Google Code user to a GitLab user
%p
<code>"johnsmith@example.com": "@johnsmith"</code>
will add "By <a href="#">@johnsmith</a>" to all issues and comments originally created by johnsmith@example.com,
and will set <a href="#">@johnsmith</a> as the assignee on all issues originally assigned to johnsmith@example.com.
%li
%strong Map a Google Code user to a full name
%p
<code>"johnsmith@example.com": "John Smith"</code>
will add "By John Smith" to all issues and comments originally created by johnsmith@example.com.
%li
%strong Map a Google Code user to a full email address
%p
<code>"johnsmith@example.com": "johnsmith@example.com"</code>
will add "By <a href="#">johnsmith@example.com</a>" to all issues and comments originally created by johnsmith@example.com.
By default, the email address or username is masked to ensure the user's privacy. Use this option if you want to show the full email address.
.form-group .form-group
.col-sm-12 .col-sm-12
......
...@@ -30,7 +30,10 @@ module Gitlab ...@@ -30,7 +30,10 @@ module Gitlab
def user_map def user_map
@user_map ||= begin @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) import_data = project.import_data.try(:data)
stored_user_map = import_data["user_map"] if import_data stored_user_map = import_data["user_map"] if import_data
...@@ -203,25 +206,25 @@ module Gitlab ...@@ -203,25 +206,25 @@ module Gitlab
end end
def linkify_issues(s) 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 end
def escape_for_markdown(s) def escape_for_markdown(s)
s = s.gsub("*", "\\*") # No headings and lists
s = s.gsub("#", "\\#") s = s.gsub(/^#/, "\\#")
s = s.gsub(/^-/, "\\-")
# No inline code
s = s.gsub("`", "\\`") s = s.gsub("`", "\\`")
s = s.gsub(":", "\\:")
s = s.gsub("-", "\\-") # Carriage returns make me sad
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("\r", "") s = s.gsub("\r", "")
# Markdown ignores single newlines, but we need them as <br />.
s = s.gsub("\n", " \n") s = s.gsub("\n", " \n")
s s
end end
...@@ -276,11 +279,18 @@ module Gitlab ...@@ -276,11 +279,18 @@ module Gitlab
if raw_updates.has_key?("blockedOn") if raw_updates.has_key?("blockedOn")
blocked_ons = raw_updates["blockedOn"].map do |raw_blocked_on| blocked_ons = raw_updates["blockedOn"].map do |raw_blocked_on|
name, id = raw_blocked_on.split(":", 2) name, id = raw_blocked_on.split(":", 2)
deleted = name.start_with?("-")
name = name[1..-1] if deleted
text =
if name == project.import_source if name == project.import_source
"##{id}" "##{id}"
else else
"#{project.namespace.path}/#{name}##{id}" "#{project.namespace.path}/#{name}##{id}"
end end
text = "~~#{text}~~" if deleted
text
end end
updates << "*Blocked on: #{blocked_ons.join(", ")}*" updates << "*Blocked on: #{blocked_ons.join(", ")}*"
end end
...@@ -288,11 +298,18 @@ module Gitlab ...@@ -288,11 +298,18 @@ module Gitlab
if raw_updates.has_key?("blocking") if raw_updates.has_key?("blocking")
blockings = raw_updates["blocking"].map do |raw_blocked_on| blockings = raw_updates["blocking"].map do |raw_blocked_on|
name, id = raw_blocked_on.split(":", 2) name, id = raw_blocked_on.split(":", 2)
deleted = name.start_with?("-")
name = name[1..-1] if deleted
text =
if name == project.import_source if name == project.import_source
"##{id}" "##{id}"
else else
"#{project.namespace.path}/#{name}##{id}" "#{project.namespace.path}/#{name}##{id}"
end end
text = "~~#{text}~~" if deleted
text
end end
updates << "*Blocking: #{blockings.join(", ")}*" updates << "*Blocking: #{blockings.join(", ")}*"
end end
...@@ -340,7 +357,7 @@ module Gitlab ...@@ -340,7 +357,7 @@ module Gitlab
def format_issue_body(author, date, content, attachments) def format_issue_body(author, date, content, attachments)
body = [] body = []
body << "*By #{author} on #{date}*" body << "*By #{author} on #{date} (imported from Google Code)*"
body << "---" body << "---"
if content.blank? if content.blank?
......
...@@ -57,10 +57,11 @@ describe Gitlab::GoogleCodeImport::Importer do ...@@ -57,10 +57,11 @@ describe Gitlab::GoogleCodeImport::Importer do
expect(issue.label_names).to include("Type: Enhancement") expect(issue.label_names).to include("Type: Enhancement")
expect(issue.title).to eq("Scrolling through tasks") expect(issue.title).to eq("Scrolling through tasks")
expect(issue.state).to eq("closed") expect(issue.state).to eq("closed")
expect(issue.description).to include("schattenpr...") expect(issue.description).to include("schattenpr\\.\\.\\.")
expect(issue.description).to include("November 18, 2009 00:20") expect(issue.description).to include("November 18, 2009 00:20")
expect(issue.description).to include('I like to scroll through the tasks with my scrollwheel \(like in fluxbox\).') expect(issue.description).to include("Google Code")
expect(issue.description).to include('Patch is attached that adds two new mouse\-actions \(next\_taskprev\_task\)') expect(issue.description).to include('I like to scroll through the tasks with my scrollwheel (like in fluxbox).')
expect(issue.description).to include('Patch is attached that adds two new mouse-actions (next_task+prev_task)')
expect(issue.description).to include('that can be used for exactly that purpose.') expect(issue.description).to include('that can be used for exactly that purpose.')
expect(issue.description).to include('all the best!') expect(issue.description).to include('all the best!')
expect(issue.description).to include('[tint2_task_scrolling.diff](https://storage.googleapis.com/google-code-attachments/tint2/issue-169/comment-0/tint2_task_scrolling.diff)') expect(issue.description).to include('[tint2_task_scrolling.diff](https://storage.googleapis.com/google-code-attachments/tint2/issue-169/comment-0/tint2_task_scrolling.diff)')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment