Class: Danger::Runner
- Inherits:
-
CLAide::Command
- Object
- CLAide::Command
- Danger::Runner
show all
- Defined in:
- lib/danger/commands/runner.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/danger/commands/runner.rb', line 15
def initialize(argv)
dangerfile = argv.option('dangerfile', 'Dangerfile')
@dangerfile_path = dangerfile if File.exist? dangerfile
@base = argv.option('base')
@head = argv.option('head')
@danger_id = argv.option('danger_id', 'danger')
@cork = Cork::Board.new(silent: argv.option('silent', false),
verbose: argv.option('verbose', false))
super
end
|
Instance Attribute Details
#cork ⇒ Object
Returns the value of attribute cork.
13
14
15
|
# File 'lib/danger/commands/runner.rb', line 13
def cork
@cork
end
|
Class Method Details
.options ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/danger/commands/runner.rb', line 33
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'],
['--danger_id=<id>', 'The identifier of this Danger instance']
].concat(super)
end
|
.report_error(exception) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/danger/commands/runner.rb', line 80
def self.report_error(exception)
raise exception if exception.kind_of?(SystemExit)
message = "#{exception.message.red} (#{exception.class.to_s.yellow})"
if exception.backtrace
danger_lib = File.expand_path('../../..', __FILE__)
message << "\n\t" << exception.backtrace.reverse_each.
drop_while { |bt| !bt.start_with?(danger_lib) }.reverse.
join("\n\t")
end
abort(message)
end
|
Instance Method Details
#post_results(dm) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/danger/commands/runner.rb', line 72
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], danger_id: @danger_id)
end
|
#run ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/danger/commands/runner.rb', line 42
def run
env = EnvironmentManager.new(ENV)
dm = Dangerfile.new(env, cork)
if dm.env.pr?
dm.verbose = verbose
dm.init_plugins
dm.env.fill_environment_vars
begin
dm.env.ensure_danger_branches_are_setup
ci_base = @base || EnvironmentManager.danger_base_branch
ci_head = @head || EnvironmentManager.danger_head_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
cork.puts "Not a Pull Request - skipping `danger` run"
end
end
|
#validate! ⇒ Object
26
27
28
29
30
31
|
# File 'lib/danger/commands/runner.rb', line 26
def validate!
super
if self.class == Runner && !@dangerfile_path
help! "Could not find a Dangerfile."
end
end
|