Sha256: 04e472189024b71d05df316f0ae19abfadbea596574432b27a90e54538d2d8d6

Contents?: true

Size: 884 Bytes

Versions: 1

Compression:

Stored size: 884 Bytes

Contents

module Danger
  # Identify todos in a set of diffs
  class DiffTodoFinder
    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)
      todos = []
      diffs.each do |diff|
        matches = diff.patch.match(TODO_REGEXP)
        next if matches.nil?

        text = matches[1] if matches[1]
        todos << Todo.new(diff.path, text.strip)
      end
      todos
    end

    class Todo < Struct.new(:file, :text)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danger-todoist-0.1.0 lib/todoist/diff_todo_finder.rb