lib/todoist/plugin.rb in danger-todoist-0.1.0 vs lib/todoist/plugin.rb in danger-todoist-0.2.0
- old
+ new
@@ -1,16 +1,20 @@
module Danger
#
# This is a danger plugin to detect any TODO/FIXME entries left in the code.
#
- # @example Ensure there are no TODOS left in the modified code
+ # @example Ensure, by warning, there are no TODOS left in the modified code
#
# todoist.warn_for_todos
#
- # @example Set custom warning message
+ # @example Ensure, by failing the build, no TODOS left in the modified code
#
- # todois.message = "Please fix all TODOS"
+ # todoist.fail_for_todos
+ #
+ # @example Set custom warning message for warning
+ #
+ # todoist.message = "Please fix all TODOS"
# todoist.warn_for_todos
#
# @example List every todo item
#
# todoist.warn_for_todos
@@ -34,16 +38,20 @@
# Adds a warning if there are todos found in the modified code
#
# @return [void]
#
def warn_for_todos
- @todos = []
- return if files_of_interest.empty?
+ call_method_for_todos(:warn)
+ end
- @todos = DiffTodoFinder.new.find_diffs_containing_todos(diffs_of_interest)
-
- warn(message) unless @todos.empty?
+ #
+ # Adds an error if there are todos found in the modified code
+ #
+ # @return [void]
+ #
+ def fail_for_todos
+ call_method_for_todos(:fail)
end
#
# Adds a list of offending files to the danger comment
#
@@ -60,9 +68,18 @@
markdown("- #{todo.file}#{text}")
end
end
private
+
+ def call_method_for_todos(method)
+ @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
end