Class: Danger::DangerfileDangerPlugin

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

Overview

A way to interact with Danger herself. Offering APIs to import plugins, and Dangerfiles from muliple sources.

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")

Run a Dangerfile from inside a sub-folder


danger.import_dangerfile(path: "path/to/Dangerfile")

Run a Dangerfile from inside a gem


danger.import_dangerfile(gem: "ruby-grape-danger")

Run a Dangerfile from inside a repo


danger.import_dangerfile(gitlab: "ruby-grape/danger")

Run a Dangerfile from inside a repo branch and path


danger.import_dangerfile(github: "ruby-grape/danger", branch: "custom", path: "path/to/Dangerfile")

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:



43
44
45
# File 'lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb', line 43

def self.instance_name
  "danger"
end

Instance Method Details

#import_dangerfile(opts) ⇒ void

This method returns an undefined value.

Import a Dangerfile.

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :github (String)

    GitHub repo

  • :gitlab (String)

    GitLab repo

  • :gem (String)

    Gem name

  • :path (String)

    Path to Dangerfile



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb', line 74

def import_dangerfile(opts)
  if opts.kind_of?(String)
    warn "Use `import_dangerfile(github: '#{opts}')` instead of `import_dangerfile '#{opts}'`."
    import_dangerfile_from_github(opts)
  elsif opts.kind_of?(Hash)
    if opts.key?(:github) || opts.key?(:gitlab)
      import_dangerfile_from_github(opts[:github] || opts[:gitlab], opts[:branch], opts[:path])
    elsif opts.key?(:path)
      import_dangerfile_from_path(opts[:path])
    elsif opts.key?(:gem)
      import_dangerfile_from_gem(opts[:gem])
    else
      raise "`import` requires a Hash with either :github or :gem"
    end
  else
    raise "`import` requires a Hash" unless opts.kind_of?(Hash)
  end
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.



55
56
57
58
59
60
61
62
63
# File 'lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb', line 55

def import_plugin(path_or_url)
  raise "`import_plugin` 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

#scm_providerSymbol

Returns the name of the current SCM Provider being used.

Returns:

  • (Symbol)

    The name of the SCM Provider used for the active repository.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb', line 96

def scm_provider
  return :unknown unless env.request_source

  case env.request_source
  when Danger::RequestSources::GitHub
    :github
  when Danger::RequestSources::GitLab
    :gitlab
  when Danger::RequestSources::BitbucketServer
    :bitbucket_server
  when Danger::RequestSources::BitbucketCloud
    :bitbucket_cloud
  when Danger::RequestSources::VSTS
    :vsts
  else
    :unknown
  end
end