Class: Danger::DangerfileMessagingPlugin

Inherits:
Plugin
  • Object
show all
Defined in:
lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb

Core collapse

Instance Method Summary collapse

Methods inherited from Plugin

instance_name, #method_missing

Constructor Details

#initialize(dangerfile) ⇒ DangerfileMessagingPlugin

Returns a new instance of DangerfileMessagingPlugin.



6
7
8
9
10
11
12
13
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 6

def initialize(dangerfile)
  super(dangerfile)

  @warnings = []
  @errors = []
  @messages = []
  @markdowns = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Danger::Plugin

Instance Method Details

#fail(message, sticky: true) ⇒ Object

Declares a CI blocking error

Parameters:

  • message (String)

    The message to present to the user

  • sticky (Boolean) (defaults to: true)

    Whether the message should be kept after it was fixed, defaults to ‘true`.



58
59
60
61
62
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 58

def fail(message, sticky: true)
  return if should_ignore_violation(message)
  @errors << Violation.new(message, sticky)
  puts "Raising error '#{message}'"
end

#markdown(message) ⇒ Object

Print markdown to below the table

Parameters:

  • message (String)

    The markdown based message to be printed below the table



20
21
22
23
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 20

def markdown(message)
  @markdowns << message
  puts "Printing markdown #{message}"
end

#message(message, sticky: true) ⇒ Object

Print out a generate message on the PR

Parameters:

  • message (String)

    The message to present to the user

  • sticky (Boolean) (defaults to: true)

    Whether the message should be kept after it was fixed, defaults to ‘true`.



32
33
34
35
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 32

def message(message, sticky: true)
  @messages << Violation.new(message, sticky)
  puts "Printing message '#{message}'"
end

#status_reportObject



64
65
66
67
68
69
70
71
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 64

def status_report
  {
    errors: @errors.map(&:message).clone.freeze,
    warnings: @warnings.map(&:message).clone.freeze,
    messages: @messages.map(&:message).clone.freeze,
    markdowns: @markdowns.clone.freeze
  }
end

#violation_reportObject



73
74
75
76
77
78
79
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 73

def violation_report
  {
    errors: @errors.clone.freeze,
    warnings: @warnings.clone.freeze,
    messages: @messages.clone.freeze
  }
end

#warn(message, sticky: true) ⇒ Object

Specifies a problem, but not critical

Parameters:

  • message (String)

    The message to present to the user

  • sticky (Boolean) (defaults to: true)

    Whether the message should be kept after it was fixed, defaults to ‘true`.



44
45
46
47
48
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 44

def warn(message, sticky: true)
  return if should_ignore_violation(message)
  @warnings << Violation.new(message, sticky)
  puts "Printing warning '#{message}'"
end