Module: GitHubDiff

Defined in:
lib/diff-suggester/diff/diff.rb,
lib/diff-suggester/diff/hunk.rb,
lib/diff-suggester/diff/diff_parser.rb

Defined Under Namespace

Classes: Diff, Hunk

Class Method Summary collapse

Class Method Details

.get_diff_stringObject



15
16
17
# File 'lib/diff-suggester/diff/diff_parser.rb', line 15

def get_diff_string
  return ::GitDiff.from_string(`git diff --unified=0 HEAD`)
end

.hunk(hunk) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/diff-suggester/diff/diff_parser.rb', line 19

def hunk(hunk)
  addition_lines = hunk.lines.select{|l| l.content.start_with?('+')}.map do |line|
    line.content.scan(/^\+([^+].*)/)
  end
  target_range = hunk.range_info.original_range
  return Hunk.new(body: addition_lines.join("\n"), start_line: target_range.start, end_line: target_range.start + target_range.number_of_lines)
end

.parse_from_stringObject



7
8
9
10
11
12
13
# File 'lib/diff-suggester/diff/diff_parser.rb', line 7

def parse_from_string
  diffs = get_diff_string.files.map { |file|
    hunks = file.hunks.map { |hunk| hunk(hunk) }
    Diff.new(file_path: file.b_path, hunks: hunks)
  }
  return diffs
end