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 multiple 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_project_id: 1345)

Run a Dangerfile from inside a repo branch and path


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

Import a plugin available over HTTP


custom_url = "https://custom.bitbucket.com/project-name/Dangerfile?raw"
danger.import_dangerfile(url: custom_url)

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:



48
49
50
# File 'lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb', line 48

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

  • :ref (String)

    The name of branch, tag or commit

  • :branch (String)

    Alias of :ref

  • :path (String)

    Path to Dangerfile



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb', line 81

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)
      import_dangerfile_from_github(opts[:github], opts[:ref] || opts[:branch], opts[:path])
    elsif opts.key?(:gitlab)
      import_dangerfile_from_gitlab(opts[:gitlab], opts[:ref] || opts[:branch], opts[:path])
    elsif opts.key?(:path)
      import_dangerfile_from_path(opts[:path])
    elsif opts.key?(:gem)
      import_dangerfile_from_gem(opts[:gem])
    elsif opts.key?(:url)
      import_dangerfile_from_url(opts[:url])
    else
      raise "`import` requires a Hash with either :github, :gitlab, :gem, :path or :url"
    end
  else
    raise "`import` requires a 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.



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

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.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb', line 107

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