Class: Danger::DangerfileMessagingPlugin
- Defined in:
- lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb
Overview
Provides the feedback mechanism for Danger. Danger can keep track of messages, warnings, failure and post arbitrary markdown into a comment.
The message within which Danger communicates back is amended on each run in a session.
Each of ‘message`, `warn` and `fail` have a `sticky` flag, `false` by default, which when `true` means that the message will be crossed out instead of being removed. If it’s not called again on subsequent runs.
By default, using ‘fail` would fail the corresponding build. Either via an API call, or via the return value for the danger command. If you have linters with errors for this call you can use `messaging.fail` instead.
You can optionally add ‘file` and `line` to provide inline feedback on a PR in GitHub, note that only feedback inside the PR’s diff will show up inline. Others will appear inside the main comment.
It is possible to have Danger ignore specific warnings or errors by writing ‘Danger: Ignore “[warning/error text]”`.
Sidenote: Messaging is the only plugin which adds functions to the root of the Dangerfile.
Core collapse
-
#fail(message, sticky: false, file: nil, line: nil) ⇒ void
Declares a CI blocking error.
-
#markdown(message, file: nil, line: nil) ⇒ void
Print markdown to below the table.
-
#message(message, sticky: false, file: nil, line: nil) ⇒ void
Print out a generate message on the PR.
-
#warn(message, sticky: false, file: nil, line: nil) ⇒ void
Specifies a problem, but not critical.
Reporting collapse
-
#status_report ⇒ Hash
A list of all messages passed to Danger, including the markdowns.
-
#violation_report ⇒ Hash
A list of all violations passed to Danger, we don’t anticipate users of Danger needing to use this.
Class Method Summary collapse
-
.instance_name ⇒ String
The instance name used in the Dangerfile.
Instance Method Summary collapse
-
#initialize(dangerfile) ⇒ DangerfileMessagingPlugin
constructor
A new instance of DangerfileMessagingPlugin.
Methods inherited from Plugin
all_plugins, clear_external_plugins, inherited, #method_missing
Constructor Details
#initialize(dangerfile) ⇒ DangerfileMessagingPlugin
Returns a new instance of DangerfileMessagingPlugin.
56 57 58 59 60 61 62 63 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 56 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
Class Method Details
.instance_name ⇒ String
The instance name used in the Dangerfile
68 69 70 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 68 def self.instance_name "messaging" end |
Instance Method Details
#fail(message, sticky: false, file: nil, line: nil) ⇒ void
This method returns an undefined value.
Declares a CI blocking error
138 139 140 141 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 138 def fail(, sticky: false, file: nil, line: nil) return if should_ignore_violation() @errors << Violation.new(, sticky, file, line) end |
#markdown(message, file: nil, line: nil) ⇒ void
This method returns an undefined value.
Print markdown to below the table
83 84 85 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 83 def markdown(, file: nil, line: nil) @markdowns << Markdown.new(, file, line) end |
#message(message, sticky: false, file: nil, line: nil) ⇒ void
This method returns an undefined value.
Print out a generate message on the PR
101 102 103 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 101 def (, sticky: false, file: nil, line: nil) @messages << Violation.new(, sticky, file, line) end |
#status_report ⇒ Hash
A list of all messages passed to Danger, including the markdowns.
149 150 151 152 153 154 155 156 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 149 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_report ⇒ Hash
A list of all violations passed to Danger, we don’t anticipate users of Danger needing to use this.
164 165 166 167 168 169 170 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 164 def violation_report { errors: @errors.clone.freeze, warnings: @warnings.clone.freeze, messages: @messages.clone.freeze } end |
#warn(message, sticky: false, file: nil, line: nil) ⇒ void
This method returns an undefined value.
Specifies a problem, but not critical
119 120 121 122 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 119 def warn(, sticky: false, file: nil, line: nil) return if should_ignore_violation() @warnings << Violation.new(, sticky, file, line) end |