diff options
author | Stan Hu <stanhu@gmail.com> | 2018-08-07 13:53:25 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-08-07 14:34:25 -0700 |
commit | 8c467b917537a87ae95c2fb5d3464ed4fe7e102f (patch) | |
tree | 73f0a01b196409839e94bcdaf3b95c4afa1a3bc7 /lib | |
parent | f3b36ac1171f6d170d008c52a0a324a438f3e886 (diff) | |
download | gitlab-ce-8c467b917537a87ae95c2fb5d3464ed4fe7e102f.tar.gz |
Fix Bitbucket Cloud importer omitting replies
Inline diff comments did not have the proper position, so even though
they had line codes the merge request validation would fail. Now
we cache the line position for each parent comment and use that.
Closes #50052
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/bitbucket_import/importer.rb | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb index f3999e690fa..fa0186c854c 100644 --- a/lib/gitlab/bitbucket_import/importer.rb +++ b/lib/gitlab/bitbucket_import/importer.rb @@ -188,7 +188,8 @@ module Gitlab end def import_inline_comments(inline_comments, pull_request, merge_request) - line_code_map = {} + position_map = {} + discussion_map = {} children, parents = inline_comments.partition(&:has_parent?) @@ -196,22 +197,28 @@ module Gitlab # relationships. We assume that the child can appear in any order in # the JSON. parents.each do |comment| - line_code_map[comment.iid] = generate_line_code(comment) + position_map[comment.iid] = build_position(merge_request, comment) end children.each do |comment| - line_code_map[comment.iid] = line_code_map.fetch(comment.parent_id, nil) + position_map[comment.iid] = position_map.fetch(comment.parent_id, nil) end inline_comments.each do |comment| begin attributes = pull_request_comment_attributes(comment) + attributes[:discussion_id] = discussion_map[comment.parent_id] if comment.has_parent? + attributes.merge!( - position: build_position(merge_request, comment), - line_code: line_code_map.fetch(comment.iid), + position: position_map[comment.iid], type: 'DiffNote') - merge_request.notes.create!(attributes) + note = merge_request.notes.create!(attributes) + + # We can't store a discussion ID until a note is created, so if + # replies are created before the parent the discussion ID won't be + # linked properly. + discussion_map[comment.iid] = note.discussion_id rescue StandardError => e errors << { type: :pull_request, iid: comment.iid, errors: e.message } end @@ -240,10 +247,6 @@ module Gitlab end end - def generate_line_code(pr_comment) - Gitlab::Git.diff_line_code(pr_comment.file_path, pr_comment.new_pos, pr_comment.old_pos) - end - def pull_request_comment_attributes(comment) { project: project, |