Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-15 00:13:48 +0300
committerDouwe Maan <douwe@gitlab.com>2015-04-15 00:13:48 +0300
commit2f797a140b9e4c2a5cc6b86b923cd3ff70e6d7e9 (patch)
tree5e558f37002158f2f7fa4ac70832ec6d53855ffe /lib/gitlab/google_code_import
parent1abda4458e28a4ad2c7232e1836d9dda186a7794 (diff)
Skip issue comment when its content, updates and attachments are empty.
Diffstat (limited to 'lib/gitlab/google_code_import')
-rw-r--r--lib/gitlab/google_code_import/importer.rb100
1 files changed, 61 insertions, 39 deletions
diff --git a/lib/gitlab/google_code_import/importer.rb b/lib/gitlab/google_code_import/importer.rb
index 730fbb8606b..3b506efddcf 100644
--- a/lib/gitlab/google_code_import/importer.rb
+++ b/lib/gitlab/google_code_import/importer.rb
@@ -79,25 +79,13 @@ module Gitlab
author = user_map[raw_issue["author"]["name"]]
date = DateTime.parse(raw_issue["published"]).to_formatted_s(:long)
- body = []
- body << "*By #{author} on #{date}*"
- body << "---"
-
comments = raw_issue["comments"]["items"]
-
issue_comment = comments.shift
- content = format_content(issue_comment["content"])
- if content.blank?
- content = "*(No description has been entered for this issue)*"
- end
- body << content
-
+ content = format_content(issue_comment["content"])
attachments = format_attachments(raw_issue["id"], 0, issue_comment["attachments"])
- if attachments.any?
- body << "---"
- body += attachments
- end
+
+ body = format_issue_body(author, date, content, attachments)
labels = []
raw_issue["labels"].each do |label|
@@ -113,7 +101,7 @@ module Gitlab
issue = project.issues.create!(
title: raw_issue["title"],
- description: body.join("\n\n"),
+ description: body,
author_id: project.creator_id,
state: raw_issue["state"] == "closed" ? "closed" : "opened"
)
@@ -129,35 +117,28 @@ module Gitlab
comments.each do |raw_comment|
next if raw_comment.has_key?("deletedBy")
- author = user_map[raw_comment["author"]["name"]]
- date = DateTime.parse(raw_comment["published"]).to_formatted_s(:long)
-
- body = []
- body << "*Comment #{raw_comment["id"]} by #{author} on #{date}*"
- body << "---"
+ content = format_content(raw_comment["content"])
+ updates = format_updates(raw_comment["updates"])
+ attachments = format_attachments(issue.iid, raw_comment["id"], raw_comment["attachments"])
- content = format_content(raw_comment["content"])
- if content.blank?
- content = "*(No comment has been entered for this change)*"
- end
- body << content
+ next if content.blank? && updates.blank? && attachments.blank?
- updates = format_updates(raw_comment["updates"])
- if updates.any?
- body << "---"
- body += updates
- end
+ author = user_map[raw_comment["author"]["name"]]
+ date = DateTime.parse(raw_comment["published"]).to_formatted_s(:long)
- attachments = format_attachments(issue.iid, raw_comment["id"], raw_comment["attachments"])
- if attachments.any?
- body << "---"
- body += attachments
- end
+ body = format_issue_comment_body(
+ raw_comment["id"],
+ author,
+ date,
+ content,
+ updates,
+ attachments
+ )
- comment = issue.notes.create!(
+ issue.notes.create!(
project_id: project.id,
author_id: project.creator_id,
- note: body.join("\n\n")
+ note: body
)
end
end
@@ -324,6 +305,47 @@ module Gitlab
text
end.compact
end
+
+ def format_issue_comment_body(id, author, date, content, updates, attachments)
+ body = []
+ body << "*Comment #{id} by #{author} on #{date}*"
+ body << "---"
+
+ if content.blank?
+ content = "*(No comment has been entered for this change)*"
+ end
+ body << content
+
+ if updates.any?
+ body << "---"
+ body += updates
+ end
+
+ if attachments.any?
+ body << "---"
+ body += attachments
+ end
+
+ body.join("\n\n")
+ end
+
+ def format_issue_body(author, date, content, attachments)
+ body = []
+ body << "*By #{author} on #{date}*"
+ body << "---"
+
+ if content.blank?
+ content = "*(No description has been entered for this issue)*"
+ end
+ body << content
+
+ if attachments.any?
+ body << "---"
+ body += attachments
+ end
+
+ body.join("\n\n")
+ end
end
end
end