Class: Danger::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/danger_core/executor.rb

Instance Method Summary collapse

Constructor Details

#initialize(system_env) ⇒ Executor

Returns a new instance of Executor.



3
4
5
# File 'lib/danger/danger_core/executor.rb', line 3

def initialize(system_env)
  @system_env = system_env
end

Instance Method Details

#run(env: nil, dm: nil, cork: nil, base: nil, head: nil, dangerfile_path: nil, danger_id: nil, new_comment: nil, fail_on_errors: nil, fail_if_no_pr: nil, remove_previous_comments: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/danger/danger_core/executor.rb', line 7

def run(env: nil,
        dm: nil,
        cork: nil,
        base: nil,
        head: nil,
        dangerfile_path: nil,
        danger_id: nil,
        new_comment: nil,
        fail_on_errors: nil,
        fail_if_no_pr: nil,
        remove_previous_comments: nil)
  # Create a silent Cork instance if cork is nil, as it's likely a test
  cork ||= Cork::Board.new(silent: false, verbose: false)

  # Run some validations
  validate!(cork, fail_if_no_pr: fail_if_no_pr)

  # OK, we now know that Danger can run in this environment
  env ||= EnvironmentManager.new(system_env, cork, danger_id)
  dm ||= Dangerfile.new(env, cork)

  ran_status = dm.run(
    base_branch(base),
    head_branch(head),
    dangerfile_path,
    danger_id,
    new_comment,
    remove_previous_comments
  )

  # By default Danger will use the status API to fail a build,
  # allowing execution to continue, this behavior isn't always
  # optimal for everyone.
  exit(1) if fail_on_errors && ran_status
end

#validate!(cork, fail_if_no_pr: false) ⇒ Object



43
44
45
46
# File 'lib/danger/danger_core/executor.rb', line 43

def validate!(cork, fail_if_no_pr: false)
  validate_ci!
  validate_pr!(cork, fail_if_no_pr)
end