Class: CleoQualityReview::DiffMap

Inherits:
Object
  • Object
show all
Defined in:
lib/cleo_quality_review/diff_map.rb

Overview

Maps a unified git diff to right-side line numbers that GitHub can comment on

Defined Under Namespace

Classes: DiffParser

Constant Summary collapse

HUNK_HEADER =
/^@@ -\d+(?:,\d+)? \+(?<line>\d+)(?:,\d+)? @@/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(diff) ⇒ DiffMap

Returns a new instance of DiffMap.

Parameters:

  • diff (String)

    unified git diff content



73
74
75
76
77
# File 'lib/cleo_quality_review/diff_map.rb', line 73

def initialize(diff)
  @diff = diff.to_s
  @commentable_lines = Hash.new { |hash, key| hash[key] = Set.new }
  parse
end

Instance Method Details

#commentable?(filepath, line) ⇒ Boolean

Parameters:

  • filepath (String)

    repository-relative file path

  • line (Integer)

    right-side line number

Returns:

  • (Boolean)


83
84
85
# File 'lib/cleo_quality_review/diff_map.rb', line 83

def commentable?(filepath, line)
  commentable_lines[filepath.to_s].include?(line.to_i)
end