Commit c1ee4595 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix_diff_line_comments' into 'master'

Fix: A diff comment on a change at last line of a file shows as two comments in discussion

Closes #32353

See merge request !11802
parents 8e4ba54a b417fc03
...@@ -66,12 +66,12 @@ module DiffHelper ...@@ -66,12 +66,12 @@ module DiffHelper
discussions_left = discussions_right = nil discussions_left = discussions_right = nil
if left && (left.unchanged? || left.removed?) if left && (left.unchanged? || left.discussable?)
line_code = diff_file.line_code(left) line_code = diff_file.line_code(left)
discussions_left = @grouped_diff_discussions[line_code] discussions_left = @grouped_diff_discussions[line_code]
end end
if right && right.added? if right&.discussable?
line_code = diff_file.line_code(right) line_code = diff_file.line_code(right)
discussions_right = @grouped_diff_discussions[line_code] discussions_right = @grouped_diff_discussions[line_code]
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
- discussions = local_assigns.fetch(:discussions, nil) - discussions = local_assigns.fetch(:discussions, nil)
- type = line.type - type = line.type
- line_code = diff_file.line_code(line) - line_code = diff_file.line_code(line)
- if discussions && !line.meta? - if discussions && line.discussable?
- line_discussions = discussions[line_code] - line_discussions = discussions[line_code]
%tr.line_holder{ class: type, id: (line_code unless plain) } %tr.line_holder{ class: type, id: (line_code unless plain) }
- case type - case type
......
---
title: 'Fix: A diff comment on a change at last line of a file shows as two comments
in discussion'
merge_request:
author:
...@@ -59,6 +59,10 @@ module Gitlab ...@@ -59,6 +59,10 @@ module Gitlab
type == 'match' type == 'match'
end end
def discussable?
!['match', 'new-nonewline', 'old-nonewline'].include?(type)
end
def as_json(opts = nil) def as_json(opts = nil)
{ {
type: type, type: type,
......
...@@ -129,6 +129,33 @@ describe DiffHelper do ...@@ -129,6 +129,33 @@ describe DiffHelper do
end end
end end
describe '#parallel_diff_discussions' do
let(:discussion) { { 'abc_3_3' => 'comment' } }
let(:diff_file) { double(line_code: 'abc_3_3') }
before do
helper.instance_variable_set(:@grouped_diff_discussions, discussion)
end
it 'does not put comments on nonewline lines' do
left = Gitlab::Diff::Line.new('\\nonewline', 'old-nonewline', 3, 3, 3)
right = Gitlab::Diff::Line.new('\\nonewline', 'new-nonewline', 3, 3, 3)
result = helper.parallel_diff_discussions(left, right, diff_file)
expect(result).to eq([nil, nil])
end
it 'puts comments on added lines' do
left = Gitlab::Diff::Line.new('\\nonewline', 'old-nonewline', 3, 3, 3)
right = Gitlab::Diff::Line.new('new line', 'add', 3, 3, 3)
result = helper.parallel_diff_discussions(left, right, diff_file)
expect(result).to eq([nil, 'comment'])
end
end
describe "#diff_match_line" do describe "#diff_match_line" do
let(:old_pos) { 40 } let(:old_pos) { 40 }
let(:new_pos) { 50 } let(:new_pos) { 50 }
......
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