lib/todoist/plugin.rb in danger-todoist-0.2.0 vs lib/todoist/plugin.rb in danger-todoist-0.3.0
- old
+ new
@@ -18,10 +18,14 @@
# @example List every todo item
#
# todoist.warn_for_todos
# todoist.print_todos_table
#
+ # @example Do anything with the todos. Todos have `text` and `file` properties
+ #
+ # todoist.todos.each { |todo| puts todo.text }
+ #
# @see hanneskaeufler/danger-todoist
# @tags todos, fixme
#
class DangerTodoist < Plugin
DEFAULT_MESSAGE = "There remain todo items in the modified code.".freeze
@@ -56,29 +60,42 @@
# Adds a list of offending files to the danger comment
#
# @return [void]
#
def print_todos_table
- return if @todos.nil?
+ find_todos if @todos.nil?
return if @todos.empty?
markdown("#### Todos left in files")
@todos.each do |todo|
text = ": #{todo.text}" if todo.text
markdown("- #{todo.file}#{text}")
end
end
+ #
+ # Returns the list of todos in the current diff set
+ #
+ # @return [Array of todos]
+ #
+ def todos
+ find_todos if @todos.nil?
+ @todos
+ end
+
private
def call_method_for_todos(method)
+ find_todos if @todos.nil?
+ public_send(method, message, sticky: false) unless @todos.empty?
+ end
+
+ def find_todos
@todos = []
return if files_of_interest.empty?
@todos = DiffTodoFinder.new.find_diffs_containing_todos(diffs_of_interest)
-
- public_send(method, message, sticky: false) unless @todos.empty?
end
def message
return @message unless @message.nil?
DEFAULT_MESSAGE