Class: Danger::DangerfileDangerPlugin

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

Overview

One way to support internal plugins is via ‘plugin.import` this gives you the chance to quickly iterate without the need for building rubygems. As such, it does not have the stringent rules around documentation expected of a public plugin. It’s worth noting, that you can also have plugins inside ‘./danger_plugins` and they will be automatically imported into your Dangerfile at launch.

Examples:

Import a plugin available over HTTP


device_grid = "https://raw.githubusercontent.com/fastlane/fastlane/master/danger-device_grid/lib/device_grid/plugin.rb"
danger.import_plugin(device_grid)

Import from a local file reference


danger.import_plugin("danger/plugins/watch_plugin.rb")

Import all files inside a folder


danger.import_plugin("danger/plugins/*.rb")

See Also:

  • danger/danger

Danger collapse

Class Method Summary collapse

Methods inherited from Plugin

all_plugins, clear_external_plugins, inherited, #initialize, #method_missing

Constructor Details

This class inherits a constructor from Danger::Plugin

Dynamic Method Handling

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

Class Method Details

.instance_nameString

The instance name used in the Dangerfile

Returns:



30
31
32
# File 'lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb', line 30

def self.instance_name
  "danger"
end

Instance Method Details

#import_dangerfile(slug) ⇒ void

This method returns an undefined value.

Download and execute a remote Dangerfile.

Parameters:

  • repo (String)

    slug A slug that represents the repo where the Dangerfile is.



59
60
61
62
63
64
65
# File 'lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb', line 59

def import_dangerfile(slug)
  raise "`import` requires a string" unless slug.kind_of?(String)
  org, repo = slug.split("/")
  download_url = env.request_source.file_url(organisation: org, repository: repo, branch: "master", path: "Dangerfile")
  local_path = import_url(download_url)
  dangerfile.parse(Pathname.new(local_path))
end

#import_plugin(path_or_url) ⇒ void

This method returns an undefined value.

Download a local or remote plugin and make it usable inside the Dangerfile.

Parameters:

  • path_or_url (String)

    a local path or a https URL to the Ruby file to import a danger plugin from.



42
43
44
45
46
47
48
49
50
# File 'lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb', line 42

def import_plugin(path_or_url)
  raise "`import` requires a string" unless path_or_url.kind_of?(String)

  if path_or_url.start_with?("http")
    import_url(path_or_url)
  else
    import_local(path_or_url)
  end
end