13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/services/diff_summarization/fallback_builder.rb', line 13
def fallback_summary(diff, chunks: nil)
parsed_chunks = chunks || Commiti::DiffParser.split_by_file(diff)
files = []
parsed_chunks.each do |chunk|
current = {
path: chunk[:path].to_s,
additions: 0,
deletions: 0,
status: 'modified'
}
chunk[:diff].to_s.each_line do |line|
stripped = line.strip
current[:status] = 'added' if stripped.start_with?('new file mode')
current[:status] = 'deleted' if stripped.start_with?('deleted file mode')
current[:status] = 'renamed' if stripped.start_with?('rename from ') || stripped.start_with?('rename to ')
next if line.start_with?('diff --git ', '+++', '---', '@@')
current[:additions] += 1 if line.start_with?('+')
current[:deletions] += 1 if line.start_with?('-')
end
files << current
end
return diff.to_s[0, FALLBACK_BYTES] if files.empty?
lines = []
lines << '### Diff Overview'
lines << "- Total files changed: #{files.length}"
lines << ''
files.first(MAX_FILES_IN_SUMMARY).each do |file|
lines << "### #{file[:path]}"
lines << "- Status: #{file[:status]}"
lines << "- Added lines: #{file[:additions]}"
lines << "- Removed lines: #{file[:deletions]}"
lines << ''
end
lines << "...and #{files.length - MAX_FILES_IN_SUMMARY} more files" if files.length > MAX_FILES_IN_SUMMARY
lines.join("\n").strip
end
|