Module: Danger::Dangerfile::DSL
- Included in:
- Danger::Dangerfile
- Defined in:
- lib/danger/plugin.rb,
lib/danger/dangerfile_dsl.rb,
lib/danger/plugins/protect_files.rb
Defined Under Namespace
Classes: Plugin, ProtectFiles
Enviroment collapse
-
#env ⇒ EnvironmentManager
readonly
objects, which you can use to pull out extra bits of information.
Enviroment collapse
-
#fail(message, sticky: true) ⇒ Object
Declares a CI blocking error.
- #import(path) ⇒ Object
-
#import_local(path) ⇒ Object
Import one or more local plugins.
-
#import_url(url) ⇒ Object
Download a remote plugin and use it locally.
- #initialize ⇒ Object
-
#markdown(message) ⇒ Object
Print markdown to below the table.
-
#message(message, sticky: true) ⇒ Object
Print out a generate message on the PR.
-
#method_missing(method_sym, *arguments, &_block) ⇒ Object
When an undefined method is called, we check to see if it’s something that either the ‘scm` or the `request_source` can handle.
- #should_ignore_violation(message) ⇒ Object
-
#warn(message, sticky: true) ⇒ Object
Specifies a problem, but not critical.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &_block) ⇒ Object
When an undefined method is called, we check to see if it’s something that either the ‘scm` or the `request_source` can handle. This opens us up to letting those object extend themselves naturally. This will also look for plugins
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/danger/dangerfile_dsl.rb', line 114 def method_missing(method_sym, *arguments, &_block) # SCM Source if AvailableValues.scm.include?(method_sym) return env.scm.send(method_sym) end # Request Source if AvailableValues.request_source.include?(method_sym) return env.request_source.send(method_sym) end # Plugins class_name = method_sym.to_s.danger_class if Danger::Dangerfile::DSL.const_defined?(class_name) plugin_ref = Danger::Dangerfile::DSL.const_get(class_name) if plugin_ref < Plugin plugin_ref.new(self).run(*arguments) else raise "'#{method_sym}' is not a valid danger plugin".red end else raise "Unknown method '#{method_sym}', please check out the documentation for available plugins".red end end |
Instance Attribute Details
#env ⇒ EnvironmentManager (readonly)
objects, which you can use to pull out extra bits of information. Warning the api of these objects is not considered a part of the Dangerfile public API, and is viable to change occasionally on the whims of developers.
12 13 14 |
# File 'lib/danger/dangerfile_dsl.rb', line 12 def env @env end |
Instance Method Details
#fail(message, sticky: true) ⇒ Object
Declares a CI blocking error
72 73 74 75 76 |
# File 'lib/danger/dangerfile_dsl.rb', line 72 def fail(, sticky: true) return if should_ignore_violation() self.errors << Violation.new(, sticky) puts "Raising error '#{}'" end |
#import(path) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/danger/dangerfile_dsl.rb', line 23 def import(path) raise "`import` requires a string" unless path.kind_of?(String) path += ".rb" unless path.end_with?(".rb") if path.start_with?("http") import_url(path) else import_local(path) end end |
#import_local(path) ⇒ Object
Import one or more local plugins
56 57 58 59 60 |
# File 'lib/danger/dangerfile_dsl.rb', line 56 def import_local(path) Dir[path].each do |file| require File.(file) # without the expand_path it would fail if the path doesn't start with ./ end end |
#import_url(url) ⇒ Object
Download a remote plugin and use it locally
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/danger/dangerfile_dsl.rb', line 38 def import_url(url) raise "URL is not https, for security reasons `danger` only supports encrypted requests" unless url.start_with?("https://") require 'tmpdir' require 'faraday' content = Faraday.get(url) Dir.mktmpdir do |dir| path = File.join(dir, "temporary_remote_action.rb") File.write(path, content.body) import_local(path) end end |
#initialize ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/danger/dangerfile_dsl.rb', line 14 def initialize self.warnings = [] self.errors = [] self. = [] self.markdowns = [] load_default_plugins end |
#markdown(message) ⇒ Object
Print markdown to below the table
105 106 107 108 |
# File 'lib/danger/dangerfile_dsl.rb', line 105 def markdown() self.markdowns << puts "Printing markdown #{}" end |
#message(message, sticky: true) ⇒ Object
Print out a generate message on the PR
96 97 98 99 |
# File 'lib/danger/dangerfile_dsl.rb', line 96 def (, sticky: true) self. << Violation.new(, sticky) puts "Printing message '#{}'" end |
#should_ignore_violation(message) ⇒ Object
62 63 64 |
# File 'lib/danger/dangerfile_dsl.rb', line 62 def should_ignore_violation() env.request_source.ignored_violations.include? end |