Commit ee5f8f28 authored by Stan Hu's avatar Stan Hu

Fix generation of diff line positions

parent 5817c670
...@@ -34,16 +34,26 @@ module BitbucketServer ...@@ -34,16 +34,26 @@ module BitbucketServer
file_type == 'FROM' file_type == 'FROM'
end end
def added?
line_type == 'ADDED'
end
def removed?
line_type == 'REMOVED'
end
def new_pos def new_pos
return unless to? return if removed?
return unless line_position
comment_anchor['line'] line_position[1]
end end
def old_pos def old_pos
return unless from? return if added?
return unless line_position
comment_anchor['line'] line_position[0]
end end
def file_path def file_path
...@@ -52,9 +62,36 @@ module BitbucketServer ...@@ -52,9 +62,36 @@ module BitbucketServer
private 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 def comment_anchor
raw.fetch('commentAnchor', {}) raw.fetch('commentAnchor', {})
end end
def diff
raw.fetch('diff', {})
end
def diff_hunks
diff.fetch('hunks', [])
end
end end
end end
end end
...@@ -143,7 +143,7 @@ module Gitlab ...@@ -143,7 +143,7 @@ module Gitlab
attributes = pull_request_comment_attributes(reply) attributes = pull_request_comment_attributes(reply)
attributes.merge!( attributes.merge!(
position: build_position(merge_request, comment), 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, discussion_id: parent.discussion_id,
type: 'DiffNote') type: 'DiffNote')
merge_request.notes.create!(attributes) merge_request.notes.create!(attributes)
......
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