Class: Danger::Runner

Inherits:
CLAide::Command
  • Object
show all
Defined in:
lib/danger/commands/runner.rb

Direct Known Subclasses

Init, Local

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
# File 'lib/danger/commands/runner.rb', line 9

def initialize(argv)
  @dangerfile_path = "Dangerfile" if File.exist? "Dangerfile"
  @base = argv.option('base')
  @head = argv.option('head')
  super
end

Class Method Details

.optionsObject



23
24
25
26
27
28
# File 'lib/danger/commands/runner.rb', line 23

def self.options
  [
    ['--base=[master|dev|stable]', 'A branch/tag/commit to use as the base of the diff'],
    ['--head=[master|dev|stable]', 'A branch/tag/commit to use as the head']
  ].concat(super)
end

Instance Method Details

#post_results(dm) ⇒ Object



48
49
50
51
# File 'lib/danger/commands/runner.rb', line 48

def post_results(dm)
  gh = dm.env.request_source
  gh.update_pull_request!(warnings: dm.warnings, errors: dm.errors, messages: dm.messages)
end

#runObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/danger/commands/runner.rb', line 30

def run
  # The order of the following commands is *really* important
  dm = Dangerfile.new
  dm.verbose = verbose
  dm.env = EnvironmentManager.new(ENV)
  return unless dm.env.ci_source # if it's not a PR
  dm.env.fill_environment_vars

  gh = dm.env.request_source
  ci_base = @base || gh.base_commit
  ci_head = @head || gh.head_commit

  dm.env.scm.diff_for_folder(".", ci_base, ci_head)
  dm.parse Pathname.new(@dangerfile_path)

  post_results(dm)
end

#validate!Object



16
17
18
19
20
21
# File 'lib/danger/commands/runner.rb', line 16

def validate!
  super
  unless @dangerfile_path
    help! "Could not find a Dangerfile."
  end
end