Commit c4dbe61a authored by Stan Hu's avatar Stan Hu

First iteration of importing diff notes

parent 014abc9c
...@@ -10,7 +10,7 @@ module BitbucketServer ...@@ -10,7 +10,7 @@ module BitbucketServer
end end
def inline_comment? def inline_comment?
comment? && raw['commentAnchor'] comment? && comment_anchor
end end
def comment def comment
...@@ -18,9 +18,9 @@ module BitbucketServer ...@@ -18,9 +18,9 @@ module BitbucketServer
@comment ||= @comment ||=
if inline_comment? if inline_comment?
PullRequestComment.new(raw_comment) PullRequestComment.new(raw)
else else
Comment.new(raw_comment) Comment.new(raw)
end end
end end
...@@ -61,13 +61,14 @@ module BitbucketServer ...@@ -61,13 +61,14 @@ module BitbucketServer
raw.fetch('comment', {}) raw.fetch('comment', {})
end end
def comment_anchor
raw['commentAnchor']
end
def author def author
raw_comment.fetch('author', {}) raw_comment.fetch('author', {})
end end
# Anchor hash:
# {u'toHash': u'a4c2164330f2549f67c13f36a93884cf66e976be', u'fromHash': u'c5f4288162e2e6218180779c7f6ac1735bb56eab', u'fileType': u'FROM', u'diffType': u'EFFECTIVE', u'lineType': u'CONTEXT', u'path': u'CHANGELOG.md', u'line': 3, u'orphaned': False}
def created_date def created_date
comment['createdDate'] comment['createdDate']
end end
......
...@@ -22,7 +22,7 @@ module BitbucketServer ...@@ -22,7 +22,7 @@ module BitbucketServer
# } # }
class Comment < Representation::Base class Comment < Representation::Base
def id def id
raw['id'] raw_comment['id']
end end
def author_username def author_username
...@@ -34,7 +34,7 @@ module BitbucketServer ...@@ -34,7 +34,7 @@ module BitbucketServer
end end
def note def note
raw['text'] raw_comment['text']
end end
def created_at def created_at
...@@ -46,7 +46,7 @@ module BitbucketServer ...@@ -46,7 +46,7 @@ module BitbucketServer
end end
def comments def comments
workset = [raw['comments']].compact workset = [raw_comment['comments']].compact
all_comments = [] all_comments = []
until workset.empty? until workset.empty?
...@@ -64,16 +64,20 @@ module BitbucketServer ...@@ -64,16 +64,20 @@ module BitbucketServer
private private
def raw_comment
raw.fetch('comment', {})
end
def author def author
raw.fetch('author', {}) raw_comment.fetch('author', {})
end end
def created_date def created_date
raw['createdDate'] raw_comment['createdDate']
end end
def updated_date def updated_date
raw['updatedDate'] raw_comment['updatedDate']
end end
end end
end end
......
...@@ -104,7 +104,7 @@ module Gitlab ...@@ -104,7 +104,7 @@ module Gitlab
inline_comments, pr_comments = comments.partition(&:inline_comment?) inline_comments, pr_comments = comments.partition(&:inline_comment?)
# import_inline_comments(inline_comments, pull_request, merge_request) import_inline_comments(inline_comments.map(&:comment), pull_request, merge_request)
import_standalone_pr_comments(pr_comments.map(&:comment), merge_request) import_standalone_pr_comments(pr_comments.map(&:comment), merge_request)
end end
...@@ -125,17 +125,13 @@ module Gitlab ...@@ -125,17 +125,13 @@ module Gitlab
def import_inline_comments(inline_comments, pull_request, merge_request) def import_inline_comments(inline_comments, pull_request, merge_request)
line_code_map = {} line_code_map = {}
children, parents = inline_comments.partition(&:has_parent?) inline_comments.each do |comment|
line_code = generate_line_code(comment)
line_code_map[comment.id] = line_code
# The BitbucketServer API returns threaded replies as parent-child comment.comments.each do |reply|
# relationships. We assume that the child can appear in any order in line_code_map[reply.id] = line_code
# the JSON.
parents.each do |comment|
line_code_map[comment.iid] = generate_line_code(comment)
end end
children.each do |comment|
line_code_map[comment.iid] = line_code_map.fetch(comment.parent_id, nil)
end end
inline_comments.each do |comment| inline_comments.each do |comment|
...@@ -143,12 +139,12 @@ module Gitlab ...@@ -143,12 +139,12 @@ module Gitlab
attributes = pull_request_comment_attributes(comment) attributes = pull_request_comment_attributes(comment)
attributes.merge!( attributes.merge!(
position: build_position(merge_request, comment), position: build_position(merge_request, comment),
line_code: line_code_map.fetch(comment.iid), line_code: line_code_map.fetch(comment.id),
type: 'DiffNote') type: 'DiffNote')
merge_request.notes.create!(attributes) merge_request.notes.create!(attributes)
rescue StandardError => e rescue StandardError => e
errors << { type: :pull_request, iid: comment.iid, errors: e.message } errors << { type: :pull_request, id: comment.id, errors: e.message }
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