9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/devloop/diff_parser.rb', line 9
def call(diff)
_, diffs_data = diff.split("\n").reduce(["", []]) do |(file, diffs_data), line|
if line.start_with?("+++ b/")
[line[6..-1], diffs_data]
elsif line.start_with?("@@ -")
line_number = line.match(/@@ -(\d+)/)[1]
[file, diffs_data << Diff.new(relative_path(file), line_number)]
else
[file, diffs_data]
end
end.uniq
results = diffs_data.group_by do |el|
el.filename
end.map do |key, value|
line_numbers = value.map(&:line_number).map(&:to_i)
if line_numbers.include?(0) || line_numbers.include?(1)
key
else
lines_range = (line_numbers.min..line_numbers.max).to_a.join(":")
"#{key}:#{lines_range}"
end
end
res = results.reject { |result| results.include?(result.split(":").first) && result.include?(":") }
end
|