Sha256: e9b86c45d99919906534b863bc79101280f627eb055c1ebabe65fa7db4f15690

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module Danger
  # Identify todos in a set of diffs
  class DiffTodoFinder
    def initialize(keywords)
      @keywords = keywords
    end

    def find_diffs_containing_todos(diffs)
      todos = []
      regexp = todo_regexp
      diffs.each do |diff|
        matches = diff.patch.scan(regexp)
        next if matches.empty?

        matches.each do |match|
          todos << Danger::Todo.new(diff.path, match.first.strip)
        end
      end
      todos
    end

    private

    def todo_regexp
      /
      ^\+                 # we only look at additions, marked by + in diffs
      \s*                 # followed by optional space
      [^a-z0-9\+\s]+      # anything looking like a comment indicator
      (\n\+)?             # allow multiline comment markers
      \s+                 # followed by at least one space
      (#{@keywords.join("|")})       # our todo indicator
      [\s:]{1}            # followed by a space or colon
      (?<text>.*)$        # matching any text until the end of the line
    /ix
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
danger-todoist-1.2.2 lib/todoist/diff_todo_finder.rb
danger-todoist-1.2.1 lib/todoist/diff_todo_finder.rb
danger-todoist-1.2.0 lib/todoist/diff_todo_finder.rb