Class: Danger::Runner

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

Direct Known Subclasses

DangerfileCommand, DryRun, Init, Local, PR, Staging, Systems

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/danger/commands/runner.rb', line 36

def initialize(argv)
  dangerfile = argv.option("dangerfile", "Dangerfile")
  @dangerfile_path = dangerfile if File.exist?(dangerfile)
  @base = argv.option("base")
  @head = argv.option("head")
  @fail_on_errors = argv.option("fail-on-errors", false)
  @fail_if_no_pr = argv.option("fail-if-no-pr", false)
  @new_comment = argv.flag?("new-comment")
  @remove_previous_comments = argv.flag?("remove-previous-comments")
  @danger_id = argv.option("danger_id", "danger")
  @cork = Cork::Board.new(silent: argv.option("silent", false),
                          verbose: argv.option("verbose", false))
  adjust_colored2_output(argv)
  super
end

Instance Attribute Details

#corkObject

Returns the value of attribute cork.



28
29
30
# File 'lib/danger/commands/runner.rb', line 28

def cork
  @cork
end

Class Method Details

.optionsObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/danger/commands/runner.rb', line 59

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"],
    ["--fail-on-errors=<true|false>", "Should always fail the build process, defaults to false"],
    ["--fail-if-no-pr=<true|false>", "Should fail the build process if no PR is found (useful for CircleCI), defaults to false"],
    ["--dangerfile=<path/to/dangerfile>", "The location of your Dangerfile"],
    ["--danger_id=<id>", "The identifier of this Danger instance"],
    ["--new-comment", "Makes Danger post a new comment instead of editing its previous one"],
    ["--remove-previous-comments", "Removes all previous comment and create a new one in the end of the list"]
  ].concat(super)
end

Instance Method Details

#runObject



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/danger/commands/runner.rb', line 72

def run
  Executor.new(ENV).run(
    base: @base,
    head: @head,
    dangerfile_path: @dangerfile_path,
    danger_id: @danger_id,
    new_comment: @new_comment,
    fail_on_errors: @fail_on_errors,
    fail_if_no_pr: @fail_if_no_pr,
    remove_previous_comments: @remove_previous_comments
  )
end

#validate!Object



52
53
54
55
56
57
# File 'lib/danger/commands/runner.rb', line 52

def validate!
  super
  if self.instance_of?(Runner) && !@dangerfile_path
    help!("Could not find a Dangerfile.")
  end
end