Commit c903f23f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Split complex methods in GoogleCodeImport::Importer

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent ea6a78ef
...@@ -30,7 +30,7 @@ module Gitlab ...@@ -30,7 +30,7 @@ module Gitlab
def user_map def user_map
@user_map ||= begin @user_map ||= begin
user_map = Hash.new do |hash, user| user_map = Hash.new do |hash, user|
# Replace ... by \.\.\., so `johnsm...@gmail.com` isn't autolinked. # Replace ... by \.\.\., so `johnsm...@gmail.com` isn't autolinked.
Client.mask_email(user).sub("...", "\\.\\.\\.") Client.mask_email(user).sub("...", "\\.\\.\\.")
end end
...@@ -76,18 +76,7 @@ module Gitlab ...@@ -76,18 +76,7 @@ module Gitlab
attachments = format_attachments(raw_issue["id"], 0, issue_comment["attachments"]) attachments = format_attachments(raw_issue["id"], 0, issue_comment["attachments"])
body = format_issue_body(author, date, content, attachments) body = format_issue_body(author, date, content, attachments)
labels = import_issue_labels(raw_issue)
labels = []
raw_issue["labels"].each do |label|
name = nice_label_name(label)
labels << name
unless @known_labels.include?(name)
create_label(name)
@known_labels << name
end
end
labels << nice_status_name(raw_issue["status"])
assignee_id = nil assignee_id = nil
if raw_issue.has_key?("owner") if raw_issue.has_key?("owner")
...@@ -110,6 +99,7 @@ module Gitlab ...@@ -110,6 +99,7 @@ module Gitlab
assignee_id: assignee_id, assignee_id: assignee_id,
state: raw_issue["state"] == "closed" ? "closed" : "opened" state: raw_issue["state"] == "closed" ? "closed" : "opened"
) )
issue.add_labels_by_names(labels) issue.add_labels_by_names(labels)
if issue.iid != raw_issue["id"] if issue.iid != raw_issue["id"]
...@@ -120,6 +110,23 @@ module Gitlab ...@@ -120,6 +110,23 @@ module Gitlab
end end
end end
def import_issue_labels(raw_issue)
labels = []
raw_issue["labels"].each do |label|
name = nice_label_name(label)
labels << name
unless @known_labels.include?(name)
create_label(name)
@known_labels << name
end
end
labels << nice_status_name(raw_issue["status"])
labels
end
def import_issue_comments(issue, comments) def import_issue_comments(issue, comments)
Note.transaction do Note.transaction do
while raw_comment = comments.shift while raw_comment = comments.shift
...@@ -172,7 +179,7 @@ module Gitlab ...@@ -172,7 +179,7 @@ module Gitlab
"#5cb85c" "#5cb85c"
when "Status: Started" when "Status: Started"
"#8e44ad" "#8e44ad"
when "Priority: Critical" when "Priority: Critical"
"#ffcfcf" "#ffcfcf"
when "Priority: High" when "Priority: High"
...@@ -181,7 +188,7 @@ module Gitlab ...@@ -181,7 +188,7 @@ module Gitlab
"#fff5cc" "#fff5cc"
when "Priority: Low" when "Priority: Low"
"#cfe9ff" "#cfe9ff"
when "Type: Defect" when "Type: Defect"
"#d9534f" "#d9534f"
when "Type: Enhancement" when "Type: Enhancement"
...@@ -249,8 +256,8 @@ module Gitlab ...@@ -249,8 +256,8 @@ module Gitlab
end end
if raw_updates.has_key?("cc") if raw_updates.has_key?("cc")
cc = raw_updates["cc"].map do |l| cc = raw_updates["cc"].map do |l|
deleted = l.start_with?("-") deleted = l.start_with?("-")
l = l[1..-1] if deleted l = l[1..-1] if deleted
l = user_map[l] l = user_map[l]
l = "~~#{l}~~" if deleted l = "~~#{l}~~" if deleted
...@@ -261,8 +268,8 @@ module Gitlab ...@@ -261,8 +268,8 @@ module Gitlab
end end
if raw_updates.has_key?("labels") if raw_updates.has_key?("labels")
labels = raw_updates["labels"].map do |l| labels = raw_updates["labels"].map do |l|
deleted = l.start_with?("-") deleted = l.start_with?("-")
l = l[1..-1] if deleted l = l[1..-1] if deleted
l = nice_label_name(l) l = nice_label_name(l)
l = "~~#{l}~~" if deleted l = "~~#{l}~~" if deleted
...@@ -278,45 +285,39 @@ module Gitlab ...@@ -278,45 +285,39 @@ 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) format_blocking_updates(raw_blocked_on)
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 end
updates << "*Blocked on: #{blocked_ons.join(", ")}*" updates << "*Blocked on: #{blocked_ons.join(", ")}*"
end end
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) format_blocking_updates(raw_blocked_on)
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 end
updates << "*Blocking: #{blockings.join(", ")}*" updates << "*Blocking: #{blockings.join(", ")}*"
end end
updates updates
end end
def format_blocking_updates(raw_blocked_on)
name, id = raw_blocked_on.split(":", 2)
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
def format_attachments(issue_id, comment_id, raw_attachments) def format_attachments(issue_id, comment_id, raw_attachments)
return [] unless raw_attachments return [] unless raw_attachments
...@@ -325,7 +326,7 @@ module Gitlab ...@@ -325,7 +326,7 @@ module Gitlab
filename = attachment["fileName"] filename = attachment["fileName"]
link = "https://storage.googleapis.com/google-code-attachments/#{@repo.name}/issue-#{issue_id}/comment-#{comment_id}/#{filename}" link = "https://storage.googleapis.com/google-code-attachments/#{@repo.name}/issue-#{issue_id}/comment-#{comment_id}/#{filename}"
text = "[#{filename}](#{link})" text = "[#{filename}](#{link})"
text = "!#{text}" if filename =~ /\.(png|jpg|jpeg|gif|bmp|tiff)\z/i text = "!#{text}" if filename =~ /\.(png|jpg|jpeg|gif|bmp|tiff)\z/i
text text
......
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