class Danger::MatchesInDiff

Identify todos in a single diff

Public Instance Methods

all_todos() click to toggle source
# File lib/todoist/diff_todo_finder.rb, line 53
def all_todos
  matches.map { |match| build_todo(diff.path, match) }
end
todo_matches?() click to toggle source
# File lib/todoist/diff_todo_finder.rb, line 49
def todo_matches?
  !matches.empty?
end

Private Instance Methods

build_todo(path, match) click to toggle source
# File lib/todoist/diff_todo_finder.rb, line 67
def build_todo(path, match)
  Danger::Todo.new(path, cleaned_todo_text(match), line_number(match))
end
cleaned_todo_text(match) click to toggle source
# File lib/todoist/diff_todo_finder.rb, line 71
def cleaned_todo_text(match)
  comment_indicator, _, entire_todo = match
  entire_todo.gsub(comment_indicator, "")
             .delete("\n")
             .strip
end
line_number(match) click to toggle source
# File lib/todoist/diff_todo_finder.rb, line 59
def line_number(match)
  _, _, _, first_text = match
  Patch.new(diff.patch).changed_lines.each do |line|
    return line.number if line.content.include? first_text
  end
  raise TextNotFoundInPatchError
end