lib/todoist/diff_todo_finder.rb in danger-todoist-0.0.3 vs lib/todoist/diff_todo_finder.rb in danger-todoist-0.1.0

- old
+ new

@@ -1,22 +1,29 @@ module Danger # Identify todos in a set of diffs class DiffTodoFinder - TODO_REGEXP = /\+.*(TODO|FIXME)[\s:]/i + TODO_REGEXP = / + ^\+ # we only look at additions, marked by + in diffs + \s* # followed by optional space + [^a-z0-9]* # anything looking like a comment indicator + \s+ # followed by at least one space + (TODO|FIXME) # our todo indicator + [\s:]{1} # followed by a space or colon + (?<text>.*)$ # matching any text until the end of the line + /ix def find_diffs_containing_todos(diffs) - diffs - .select { |diff| contains_new_todo(diff) } - .map { |diff| Todo.new(diff.path) } - end + todos = [] + diffs.each do |diff| + matches = diff.patch.match(TODO_REGEXP) + next if matches.nil? - private - - def contains_new_todo(diff) - # TODO: This will match removed todos as well - !(diff.patch =~ TODO_REGEXP).nil? + text = matches[1] if matches[1] + todos << Todo.new(diff.path, text.strip) + end + todos end - class Todo < Struct.new(:file) + class Todo < Struct.new(:file, :text) end end end