summaryrefslogtreecommitdiff
path: root/lib/gitlab/bitbucket_server_import
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-17 15:48:01 -0700
committerStan Hu <stanhu@gmail.com>2018-07-17 15:48:01 -0700
commit099f9fcd13b2d3e5ad8e2a7adbe8255e424cea50 (patch)
tree15ab0b32105d15347661bb9f525ec0cebc364c63 /lib/gitlab/bitbucket_server_import
parentda02df04ec8e961598a941d23782bbd8c7a6bc99 (diff)
downloadgitlab-ce-099f9fcd13b2d3e5ad8e2a7adbe8255e424cea50.tar.gz
Fallback to creating a note if DiffNote fails to import
Diffstat (limited to 'lib/gitlab/bitbucket_server_import')
-rw-r--r--lib/gitlab/bitbucket_server_import/importer.rb26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/gitlab/bitbucket_server_import/importer.rb b/lib/gitlab/bitbucket_server_import/importer.rb
index 10a2bcabb60..133b8f763ec 100644
--- a/lib/gitlab/bitbucket_server_import/importer.rb
+++ b/lib/gitlab/bitbucket_server_import/importer.rb
@@ -216,31 +216,49 @@ module Gitlab
def import_inline_comments(inline_comments, merge_request)
inline_comments.each do |comment|
position = build_position(merge_request, comment)
- parent = build_diff_note(merge_request, comment, position)
+ parent = create_diff_note(merge_request, comment, position)
next unless parent&.persisted?
discussion_id = parent.discussion_id
comment.comments.each do |reply|
- build_diff_note(merge_request, reply, position, discussion_id)
+ create_diff_note(merge_request, reply, position, discussion_id)
end
end
end
- def build_diff_note(merge_request, comment, position, discussion_id = nil)
+ def create_diff_note(merge_request, comment, position, discussion_id = nil)
attributes = pull_request_comment_attributes(comment)
attributes.merge!(
position: position,
type: 'DiffNote')
attributes[:discussion_id] = discussion_id if discussion_id
- merge_request.notes.create!(attributes)
+ note = merge_request.notes.build(attributes)
+
+ if note.valid?
+ note.save
+ return note
+ end
+
+ # Fallback to a regular comment
+ create_fallback_diff_note(merge_request, comment)
rescue StandardError => e
errors << { type: :pull_request, id: comment.id, errors: e.message }
nil
end
+ # Bitbucket Server supports the ability to comment on any line, not just the
+ # line in the diff. If we can't add the note as a DiffNote, fallback to creating
+ # a regular note.
+ def create_fallback_diff_note(merge_request, comment)
+ attributes = pull_request_comment_attributes(comment)
+ attributes[:note] = "Comment on file: #{comment.file_path}, old position: #{comment.old_pos}, new_position: #{comment.new_pos}\n\n" + attributes[:note]
+
+ merge_request.notes.create!(attributes)
+ end
+
def build_position(merge_request, pr_comment)
params = {
diff_refs: merge_request.diff_refs,