diff options
author | Stan Hu <stanhu@gmail.com> | 2018-06-28 13:48:25 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-06-28 13:48:25 -0700 |
commit | ee5f8f2830f7bdfcbd36b2368dd15b109bf29c69 (patch) | |
tree | 3830271963a15a5dc36530e13b434f3d52f16c16 /lib/bitbucket_server | |
parent | 5817c67014576fab899fac3d8478f3620af4dda2 (diff) | |
download | gitlab-ce-ee5f8f2830f7bdfcbd36b2368dd15b109bf29c69.tar.gz |
Fix generation of diff line positions
Diffstat (limited to 'lib/bitbucket_server')
-rw-r--r-- | lib/bitbucket_server/representation/pull_request_comment.rb | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/lib/bitbucket_server/representation/pull_request_comment.rb b/lib/bitbucket_server/representation/pull_request_comment.rb index a04c120b0b0..3763ba13816 100644 --- a/lib/bitbucket_server/representation/pull_request_comment.rb +++ b/lib/bitbucket_server/representation/pull_request_comment.rb @@ -34,16 +34,26 @@ module BitbucketServer file_type == 'FROM' end + def added? + line_type == 'ADDED' + end + + def removed? + line_type == 'REMOVED' + end + def new_pos - return unless to? + return if removed? + return unless line_position - comment_anchor['line'] + 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 |