Class: Danger::DiffTodoFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/todoist/diff_todo_finder.rb

Overview

Identify todos in a set of diffs

Instance Method Summary collapse

Constructor Details

#initialize(keywords) ⇒ DiffTodoFinder

Returns a new instance of DiffTodoFinder.



4
5
6
# File 'lib/todoist/diff_todo_finder.rb', line 4

def initialize(keywords)
  @regexp = todo_regexp(keywords)
end

Instance Method Details

#call(diffs) ⇒ Object

rubocop:disable Metrics/MethodLength



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/todoist/diff_todo_finder.rb', line 9

def call(diffs)
  diffs
    .map do |diff|
      # Should only look for matches *within* the changed lines of a patch
      # (lines that begin with "+"), not the entire patch.
      # The current regexp doesn't enforce this correctly in some cases.
      patch = MatchesInDiff::Patch.new(diff.patch)
      matches = patch.changed_lines
                     .map(&:content)
                     .join
                     .scan(@regexp)

      MatchesInDiff.new(diff, matches)
    end
    .select(&:todo_matches?)
    .map(&:all_todos)
    .flatten
end