Class: Danger::Runner

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

Direct Known Subclasses

Init, Local, NewPlugin

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



13
14
15
16
17
18
19
# File 'lib/danger/commands/runner.rb', line 13

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

Class Method Details

.optionsObject



28
29
30
31
32
33
34
# File 'lib/danger/commands/runner.rb', line 28

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'],
    ['--dangerfile=<path/to/dangerfile>', 'The location of your Dangerfile']
  ].concat(super)
end

Instance Method Details

#post_results(dm) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/danger/commands/runner.rb', line 66

def post_results(dm)
  gh = dm.env.request_source
  violations = dm.violation_report
  status = dm.status_report

  gh.update_pull_request!(warnings: violations[:warnings], errors: violations[:errors], messages: violations[:messages], markdowns: status[:markdowns])
end

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/danger/commands/runner.rb', line 36

def run
  env = EnvironmentManager.new(ENV)
  dm = Dangerfile.new(env)

  if dm.env.pr?
    dm.verbose = verbose
    dm.init_plugins

    dm.env.fill_environment_vars

    begin
      dm.env.ensure_danger_branches_are_setup

      # Offer the chance for a user to specify a branch through the command line
      ci_base = @base || dm.env.danger_head_branch
      ci_head = @head || dm.env.danger_base_branch
      dm.env.scm.diff_for_folder(".", from: ci_base, to: ci_head)

      dm.parse Pathname.new(@dangerfile_path)

      post_results dm
      dm.print_results
    ensure
      dm.env.clean_up
    end
  else
    puts "Not a Pull Request - skipping `danger` run"
  end
end

#validate!Object



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

def validate!
  super
  if self.class == Runner && !@dangerfile_path
    help! "Could not find a Dangerfile."
  end
end