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.
Each of ‘message`, `warn`, `fail` and `markdown` support multiple passed arguments message ’Hello’, ‘World’, file: “Dangerfile”, line: 1 warn [‘This’, ‘is’, ‘warning’], file: “Dangerfile”, line: 1 failure ‘Ooops’, ‘bad bad error’, sticky: false markdown ‘# And’, ‘# Even’, ‘# Markdown’, file: “Dangerfile”, line: 1
By default, using ‘failure` would fail the corresponding build. Either via an API call, or via the return value for the danger command. Older code examples use `fail` which is an alias of `failure`, but the default Rubocop settings would have an issue with it.
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(*failures, **options) ⇒ void
(also: #failure)
Declares a CI blocking error.
-
#markdown(*markdowns, **options) ⇒ void
Print markdown to below the table.
-
#message(*messages, **options) ⇒ void
Print out a generate message on the PR.
-
#warn(*warnings, **options) ⇒ 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.
71 72 73 74 75 76 77 78 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 71 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
83 84 85 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 83 def self.instance_name "messaging" end |
Instance Method Details
#fail(*failures, **options) ⇒ void Also known as: failure
This method returns an undefined value.
Declares a CI blocking error
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 171 def fail(*failures, **) sticky = .fetch(:sticky, false) file = .fetch(:file, nil) line = .fetch(:line, nil) failures.flatten.each do |failure| next if should_ignore_violation(failure) @errors << Violation.new(failure, sticky, file, line, type: :error) if failure end end |
#markdown(*markdowns, **options) ⇒ void
This method returns an undefined value.
Print markdown to below the table
98 99 100 101 102 103 104 105 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 98 def markdown(*markdowns, **) file = .fetch(:file, nil) line = .fetch(:line, nil) markdowns.flatten.each do |markdown| @markdowns << Markdown.new(markdown, file, line) end end |
#message(*messages, **options) ⇒ void
This method returns an undefined value.
Print out a generate message on the PR
121 122 123 124 125 126 127 128 129 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 121 def (*, **) sticky = .fetch(:sticky, false) file = .fetch(:file, nil) line = .fetch(:line, nil) .flatten.each do || @messages << Violation.new(, sticky, file, line, type: :message) if end end |
#status_report ⇒ Hash
A list of all messages passed to Danger, including the markdowns.
191 192 193 194 195 196 197 198 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 191 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.
206 207 208 209 210 211 212 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 206 def violation_report { errors: @errors.clone.freeze, warnings: @warnings.clone.freeze, messages: @messages.clone.freeze } end |
#warn(*warnings, **options) ⇒ void
This method returns an undefined value.
Specifies a problem, but not critical
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb', line 145 def warn(*warnings, **) sticky = .fetch(:sticky, false) file = .fetch(:file, nil) line = .fetch(:line, nil) warnings.flatten.each do |warning| next if should_ignore_violation(warning) @warnings << Violation.new(warning, sticky, file, line, type: :warning) if warning end end |