First iteration of importing diff notes

This commit is contained in:
Stan Hu 2018-06-28 00:50:10 -07:00
parent 014abc9c07
commit c4dbe61a84
3 changed files with 26 additions and 25 deletions

View file

@ -10,7 +10,7 @@ module BitbucketServer
end
def inline_comment?
comment? && raw['commentAnchor']
comment? && comment_anchor
end
def comment
@ -18,9 +18,9 @@ module BitbucketServer
@comment ||=
if inline_comment?
PullRequestComment.new(raw_comment)
PullRequestComment.new(raw)
else
Comment.new(raw_comment)
Comment.new(raw)
end
end
@ -61,13 +61,14 @@ module BitbucketServer
raw.fetch('comment', {})
end
def comment_anchor
raw['commentAnchor']
end
def author
raw_comment.fetch('author', {})
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
comment['createdDate']
end

View file

@ -22,7 +22,7 @@ module BitbucketServer
# }
class Comment < Representation::Base
def id
raw['id']
raw_comment['id']
end
def author_username
@ -34,7 +34,7 @@ module BitbucketServer
end
def note
raw['text']
raw_comment['text']
end
def created_at
@ -46,7 +46,7 @@ module BitbucketServer
end
def comments
workset = [raw['comments']].compact
workset = [raw_comment['comments']].compact
all_comments = []
until workset.empty?
@ -64,16 +64,20 @@ module BitbucketServer
private
def raw_comment
raw.fetch('comment', {})
end
def author
raw.fetch('author', {})
raw_comment.fetch('author', {})
end
def created_date
raw['createdDate']
raw_comment['createdDate']
end
def updated_date
raw['updatedDate']
raw_comment['updatedDate']
end
end
end

View file

@ -104,7 +104,7 @@ module Gitlab
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)
end
@ -125,17 +125,13 @@ module Gitlab
def import_inline_comments(inline_comments, pull_request, merge_request)
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
# 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)
comment.comments.each do |reply|
line_code_map[reply.id] = line_code
end
children.each do |comment|
line_code_map[comment.iid] = line_code_map.fetch(comment.parent_id, nil)
end
inline_comments.each do |comment|
@ -143,12 +139,12 @@ module Gitlab
attributes = pull_request_comment_attributes(comment)
attributes.merge!(
position: build_position(merge_request, comment),
line_code: line_code_map.fetch(comment.iid),
line_code: line_code_map.fetch(comment.id),
type: 'DiffNote')
merge_request.notes.create!(attributes)
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