class Gitlab::Dangerfiles::Engine
This class provides utility methods to import plugins and dangerfiles easily.
Attributes
dangerfile[R]
Public Class Methods
new(dangerfile)
click to toggle source
@param dangerfile [Danger::Dangerfile] A Danger::Dangerfile
object.
@example
# In your main Dangerfile: dangerfiles = Gitlab::Dangerfiles::Engine.new(self)
@return [Gitlab::Dangerfiles::Engine]
# File lib/gitlab/dangerfiles.rb, line 27 def initialize(dangerfile) @dangerfile = dangerfile end
Public Instance Methods
import_dangerfiles(rules: :all)
click to toggle source
Import available Dangerfiles
.
@param rules [Symbol, Array<String>] Can be either :all
(default) to import all rules,
or an array of rules. Available rules are: +changes_size+.
@example
# In your main Dangerfile: dangerfiles = Gitlab::Dangerfiles::Engine.new(self) # Import all rules dangerfiles.import_dangerfiles # Or import only a subset of rules dangerfiles.import_dangerfiles(rules: %w[changes_size])
# File lib/gitlab/dangerfiles.rb, line 58 def import_dangerfiles(rules: :all) filtered_rules(rules).each do |rule| danger_plugin.import_dangerfile(path: File.join(RULES_DIR, rule)) end end
import_plugins()
click to toggle source
Import all available plugins.
@example
# In your main Dangerfile: dangerfiles = Gitlab::Dangerfiles::Engine.new(self) # Import all plugins dangerfiles.import_plugins
# File lib/gitlab/dangerfiles.rb, line 39 def import_plugins danger_plugin.import_plugin(File.expand_path("../danger/plugins/*.rb", __dir__)) end
Private Instance Methods
allowed_rules()
click to toggle source
# File lib/gitlab/dangerfiles.rb, line 68 def allowed_rules return LOCAL_RULES unless helper_plugin.respond_to?(:ci?) helper_plugin.ci? ? LOCAL_RULES | CI_ONLY_RULES : LOCAL_RULES end
danger_plugin()
click to toggle source
# File lib/gitlab/dangerfiles.rb, line 80 def danger_plugin @danger_plugin ||= dangerfile.plugins[Danger::DangerfileDangerPlugin] end
filtered_rules(rules)
click to toggle source
# File lib/gitlab/dangerfiles.rb, line 74 def filtered_rules(rules) rules = EXISTING_RULES if rules == :all Array(rules).map(&:to_s) & EXISTING_RULES & allowed_rules end
helper_plugin()
click to toggle source
# File lib/gitlab/dangerfiles.rb, line 84 def helper_plugin @helper_plugin ||= dangerfile.plugins[Danger::Helper] end