Fix generation of diff line positions

This commit is contained in:
Stan Hu 2018-06-28 13:48:25 -07:00
parent 5817c67014
commit ee5f8f2830
2 changed files with 43 additions and 6 deletions

View file

@ -34,16 +34,26 @@ module BitbucketServer
file_type == 'FROM'
end
def new_pos
return unless to?
def added?
line_type == 'ADDED'
end
comment_anchor['line']
def removed?
line_type == 'REMOVED'
end
def new_pos
return if removed?
return unless line_position
line_position[1]
end
def old_pos
return unless from?
return if added?
return unless line_position
comment_anchor['line']
line_position[0]
end
def file_path
@ -52,9 +62,36 @@ module BitbucketServer
private
def line_type
comment_anchor['lineType']
end
def line_position
@line_position ||=
diff_hunks.each do |hunk|
segments = hunk.fetch('segments', [])
segments.each do |segment|
lines = segment.fetch('lines', [])
lines.each do |line|
if line['commentIds']&.include?(id)
return [line['source'], line['destination']]
end
end
end
end
end
def comment_anchor
raw.fetch('commentAnchor', {})
end
def diff
raw.fetch('diff', {})
end
def diff_hunks
diff.fetch('hunks', [])
end
end
end
end

View file

@ -143,7 +143,7 @@ module Gitlab
attributes = pull_request_comment_attributes(reply)
attributes.merge!(
position: build_position(merge_request, comment),
line_code: line_code_map.fetch(reply.id)
line_code: line_code_map.fetch(reply.id),
discussion_id: parent.discussion_id,
type: 'DiffNote')
merge_request.notes.create!(attributes)