Skip to content
Snippets Groups Projects
Commit 89623dcc authored by Oswaldo Ferreir's avatar Oswaldo Ferreir
Browse files

Comment on any expanded diff line on MRs

parent e13a3c71
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -129,15 +129,59 @@ module Gitlab
 
attr_writer :highlighted_diff_lines
 
def parse_diff_lines
Gitlab::Diff::Parser.new.parse(raw_diff.each_line, diff_file: self).to_a
end
# Array of Gitlab::Diff::Line objects
def diff_lines
@diff_lines ||=
Gitlab::Diff::Parser.new.parse(raw_diff.each_line, diff_file: self).to_a
@diff_lines ||= insert_blob_lines(parse_diff_lines)
end
def old_blob_lines
@old_blob_lines ||=
Gitlab::Diff::Parser.new.parse(old_blob.data.each_line, diff_file: self).to_a
end
def insert_blob_lines(diff_lines)
lines = old_blob_lines[(59 - 1)..(79 - 1)]
new_line_number = 80
old_line_number = 83
offset = new_line_number - old_line_number
# we should not use the positions given by the blob, because they're not correct
# when merging the content with the diff one.
# old_positions should be defined upon expansion
# Problems:
# 1. We need to fix the line code
lines.map! do |line|
Gitlab::Diff::Line.new(line.text, line.type, nil, line.old_pos - offset, line.new_pos,
parent_file: self)
end
lines_length = lines.length - 1
line = [59, lines_length].join(',')
match_line = "@@ -#{line}+#{line} @@"
old_pos = new_pos = 59
old_match_line = diff_lines[10]
new_match_line = Gitlab::Diff::Line.new(match_line, 'match', nil, old_pos, new_pos)
blob_lines = lines.unshift(new_match_line)
diff_lines = diff_lines - [old_match_line]
diff_lines.insert(10, *blob_lines)
# gambiarra: ideally we should try to use the parser with the whole content (diff+blobs)
diff_lines.each_with_index { |x, i| x.index = i }
diff_lines
end
 
def highlighted_diff_lines
@highlighted_diff_lines ||=
Gitlab::Diff::Highlight.new(self, repository: self.repository).highlight
# @highlighted_diff_lines ||=
Gitlab::Diff::Highlight.new(self, repository: self.repository).highlight
end
 
# Array[<Hash>] with right/left keys that contains Gitlab::Diff::Line objects which text is hightlighted
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@ module Gitlab
SERIALIZE_KEYS = %i(line_code rich_text text type index old_pos new_pos).freeze
 
attr_reader :line_code, :type, :index, :old_pos, :new_pos
attr_writer :rich_text
attr_writer :rich_text, :index
attr_accessor :text
 
def initialize(text, type, index, old_pos, new_pos, parent_file: nil, line_code: nil, rich_text: nil)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment