Top Level Namespace
Defined Under Namespace
Modules: HeimdalAiAnalyze
Instance Method Summary collapse
-
#changed_executable_line_numbers(chunk) ⇒ Object
New-file line numbers for lines introduced or modified on the right-hand side of the diff.
- #each_staged_file_diff(diff_text) ⇒ Object
- #merge_line_arrays(a, b) ⇒ Object
Instance Method Details
#changed_executable_line_numbers(chunk) ⇒ Object
New-file line numbers for lines introduced or modified on the right-hand side of the diff.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/heimdal_ai_analyze/git_analyze_staged_coverage.rb', line 70 def changed_executable_line_numbers(chunk) lines = [] new_ln = nil chunk.each_line do |line| if line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/ new_ln = Regexp.last_match(3).to_i next end next if line.start_with?("---", "+++", "diff ", "\\") if line.start_with?("+") && !line.start_with?("+++") lines << new_ln new_ln += 1 elsif line.start_with?("-") && !line.start_with?("---") # old side only next elsif line.start_with?(" ") new_ln += 1 end end lines.uniq.sort end |
#each_staged_file_diff(diff_text) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/heimdal_ai_analyze/git_analyze_staged_coverage.rb', line 57 def each_staged_file_diff(diff_text) diff_text.split(/(?=^diff --git )/m).each do |chunk| chunk = chunk.strip next if chunk.empty? next unless chunk =~ %r{\Adiff --git a/(.+?) b/} path = Regexp.last_match(1) yield path, chunk end end |
#merge_line_arrays(a, b) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/heimdal_ai_analyze/git_analyze_staged_coverage.rb', line 21 def merge_line_arrays(a, b) return b if a.nil? || a.empty? return a if b.nil? || b.empty? len = [a.size, b.size].max (0...len).map do |i| va = a[i] vb = b[i] if va.nil? && vb.nil? nil elsif va.nil? vb elsif vb.nil? va else [va.to_i, vb.to_i].max end end end |