lib/danger/commands/runner.rb in danger-0.7.4 vs lib/danger/commands/runner.rb in danger-0.8.0
- old
+ new
@@ -4,15 +4,17 @@
require 'danger/commands/local'
require 'danger/commands/new_plugin'
self.summary = 'Run the Dangerfile.'
self.command = 'danger'
+ self.version = Danger::VERSION
self.plugin_prefixes = %w(claide danger)
def initialize(argv)
- @dangerfile_path = "Dangerfile" if File.exist? "Dangerfile"
+ dangerfile = argv.option('dangerfile', 'Dangerfile')
+ @dangerfile_path = dangerfile if File.exist? dangerfile
@base = argv.option('base')
@head = argv.option('head')
super
end
@@ -24,39 +26,49 @@
end
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']
+ ['--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
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
+ env = EnvironmentManager.new(ENV)
+ dm = Dangerfile.new(env)
- dm.env.fill_environment_vars
- dm.env.ensure_danger_branches_are_setup
+ if dm.env.pr?
+ dm.verbose = verbose
+ dm.init_plugins
- # 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.env.fill_environment_vars
- dm.parse Pathname.new(@dangerfile_path)
+ begin
+ dm.env.ensure_danger_branches_are_setup
- post_results(dm)
+ # 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.env.clean_up
+ dm.parse Pathname.new(@dangerfile_path)
- dm.print_results
+ post_results dm
+ dm.print_results
+ ensure
+ dm.env.clean_up
+ end
+ else
+ puts "Not a Pull Request - skipping `danger` run"
+ end
end
def post_results(dm)
gh = dm.env.request_source
- gh.update_pull_request!(warnings: dm.warnings, errors: dm.errors, messages: dm.messages, markdowns: dm.markdowns)
+ 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
end
end