lib/todoist/diff_todo_finder.rb in danger-todoist-1.2.2 vs lib/todoist/diff_todo_finder.rb in danger-todoist-1.2.3
- old
+ new
@@ -11,27 +11,36 @@
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)
+ todos << Danger::Todo.new(diff.path, clean_todo_text(match))
end
end
todos
end
private
+ def clean_todo_text(match)
+ comment_indicator, _, entire_todo = match
+ entire_todo.gsub(comment_indicator, "")
+ .delete("\n")
+ .strip
+ end
+
+ # this is quite a mess now ... I knew it would haunt me.
+ # to aid debugging, this online regexr can be
+ # used: http://rubular.com/r/DPkoE2ztpn
+ # the regexp uses backreferences to match the comment indicator multiple
+ # times if possible
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
+ (?<comment_indicator>^\+\s*[^a-z0-9\+\s]+)
+ (\n\+)?\s+
+ (?<todo_indicator>#{@keywords.join("|")})[\s:]{1}
+ (?<entire_text>(?<text>[^\n]*)
+ (?<rest>\n\k<comment_indicator>\s*[\w .]*)*)
+ /ixm
end
end
end