diff options
author | Valery Sizov <valery@gitlab.com> | 2017-05-30 23:38:06 +0300 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2017-05-31 18:38:10 +0300 |
commit | 563c1ca01cf94e125a5d01669e6e8455da257246 (patch) | |
tree | fc2c4dd7f85aee83c5574be87a3387afba959da5 | |
parent | 52a3d4372c6e45e4ffb792a9fe7bfca84f3573a3 (diff) | |
download | gitlab-ce-563c1ca01cf94e125a5d01669e6e8455da257246.tar.gz |
Fix: A diff comment on a change at last line of a file shows as two comments in discussion
-rw-r--r-- | app/helpers/diff_helper.rb | 4 | ||||
-rw-r--r-- | app/views/projects/diffs/_line.html.haml | 2 | ||||
-rw-r--r-- | lib/gitlab/diff/line.rb | 4 | ||||
-rw-r--r-- | spec/helpers/diff_helper_spec.rb | 26 |
4 files changed, 33 insertions, 3 deletions
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 4c4fbdd4d39..5f3897b4f40 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -66,12 +66,12 @@ module DiffHelper discussions_left = discussions_right = nil - if left && (left.unchanged? || left.removed?) + if left && (left.unchanged? || left.discussable?) line_code = diff_file.line_code(left) discussions_left = @grouped_diff_discussions[line_code] end - if right && right.added? + if right&.discussable? line_code = diff_file.line_code(right) discussions_right = @grouped_diff_discussions[line_code] end diff --git a/app/views/projects/diffs/_line.html.haml b/app/views/projects/diffs/_line.html.haml index 7439b8a66f7..43708d22a0c 100644 --- a/app/views/projects/diffs/_line.html.haml +++ b/app/views/projects/diffs/_line.html.haml @@ -3,7 +3,7 @@ - discussions = local_assigns.fetch(:discussions, nil) - type = line.type - line_code = diff_file.line_code(line) -- if discussions && !line.meta? +- if discussions && line.discussable? - line_discussions = discussions[line_code] %tr.line_holder{ class: type, id: (line_code unless plain) } - case type diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb index 0a15c6d9358..bd52ae47e9f 100644 --- a/lib/gitlab/diff/line.rb +++ b/lib/gitlab/diff/line.rb @@ -59,6 +59,10 @@ module Gitlab type == 'match' end + def discussable? + !['match', 'new-nonewline', 'old-nonewline'].include?(type) + end + def as_json(opts = nil) { type: type, diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb index dd6566d25bb..85093f799e9 100644 --- a/spec/helpers/diff_helper_spec.rb +++ b/spec/helpers/diff_helper_spec.rb @@ -129,6 +129,32 @@ describe DiffHelper do end end + describe '#parallel_diff_discussions' do + it 'does not put comments on nonewline lines' do + discussion = {'abc_3_3' => 'comment'} + helper.instance_variable_set(:@grouped_diff_discussions, discussion) + diff_file = double(line_code: 'abc_3_3') + 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 + discussion = {'abc_3_3' => 'comment'} + helper.instance_variable_set(:@grouped_diff_discussions, discussion) + diff_file = double(line_code: 'abc_3_3') + 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 let(:old_pos) { 40 } let(:new_pos) { 50 } |