Commit 2f797a14 authored by Douwe Maan's avatar Douwe Maan

Skip issue comment when its content, updates and attachments are empty.

parent 1abda445
...@@ -79,25 +79,13 @@ module Gitlab ...@@ -79,25 +79,13 @@ module Gitlab
author = user_map[raw_issue["author"]["name"]] author = user_map[raw_issue["author"]["name"]]
date = DateTime.parse(raw_issue["published"]).to_formatted_s(:long) date = DateTime.parse(raw_issue["published"]).to_formatted_s(:long)
body = []
body << "*By #{author} on #{date}*"
body << "---"
comments = raw_issue["comments"]["items"] comments = raw_issue["comments"]["items"]
issue_comment = comments.shift issue_comment = comments.shift
content = format_content(issue_comment["content"]) content = format_content(issue_comment["content"])
if content.blank?
content = "*(No description has been entered for this issue)*"
end
body << content
attachments = format_attachments(raw_issue["id"], 0, issue_comment["attachments"]) attachments = format_attachments(raw_issue["id"], 0, issue_comment["attachments"])
if attachments.any?
body << "---" body = format_issue_body(author, date, content, attachments)
body += attachments
end
labels = [] labels = []
raw_issue["labels"].each do |label| raw_issue["labels"].each do |label|
...@@ -113,7 +101,7 @@ module Gitlab ...@@ -113,7 +101,7 @@ module Gitlab
issue = project.issues.create!( issue = project.issues.create!(
title: raw_issue["title"], title: raw_issue["title"],
description: body.join("\n\n"), description: body,
author_id: project.creator_id, author_id: project.creator_id,
state: raw_issue["state"] == "closed" ? "closed" : "opened" state: raw_issue["state"] == "closed" ? "closed" : "opened"
) )
...@@ -129,35 +117,28 @@ module Gitlab ...@@ -129,35 +117,28 @@ module Gitlab
comments.each do |raw_comment| comments.each do |raw_comment|
next if raw_comment.has_key?("deletedBy") next if raw_comment.has_key?("deletedBy")
author = user_map[raw_comment["author"]["name"]] content = format_content(raw_comment["content"])
date = DateTime.parse(raw_comment["published"]).to_formatted_s(:long) updates = format_updates(raw_comment["updates"])
attachments = format_attachments(issue.iid, raw_comment["id"], raw_comment["attachments"])
body = []
body << "*Comment #{raw_comment["id"]} by #{author} on #{date}*"
body << "---"
content = format_content(raw_comment["content"]) next if content.blank? && updates.blank? && attachments.blank?
if content.blank?
content = "*(No comment has been entered for this change)*"
end
body << content
updates = format_updates(raw_comment["updates"]) author = user_map[raw_comment["author"]["name"]]
if updates.any? date = DateTime.parse(raw_comment["published"]).to_formatted_s(:long)
body << "---"
body += updates
end
attachments = format_attachments(issue.iid, raw_comment["id"], raw_comment["attachments"]) body = format_issue_comment_body(
if attachments.any? raw_comment["id"],
body << "---" author,
body += attachments date,
end content,
updates,
attachments
)
comment = issue.notes.create!( issue.notes.create!(
project_id: project.id, project_id: project.id,
author_id: project.creator_id, author_id: project.creator_id,
note: body.join("\n\n") note: body
) )
end end
end end
...@@ -324,6 +305,47 @@ module Gitlab ...@@ -324,6 +305,47 @@ module Gitlab
text text
end.compact end.compact
end 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 end
end end
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