lib/danger/commands/local.rb in danger-0.10.0 vs lib/danger/commands/local.rb in danger-0.10.1
- old
+ new
@@ -1,25 +1,50 @@
require "danger/commands/local_helpers/http_cache"
require "faraday/http_cache"
+require "fileutils"
require "octokit"
require "tmpdir"
module Danger
class Local < Runner
self.summary = "Run the Dangerfile locally."
self.command = "local"
def initialize(argv)
- @dangerfile_path = "Dangerfile" if File.exist? "Dangerfile"
@pr_num = argv.option("use-merged-pr")
@clear_http_cache = argv.flag?("clear-http-cache", false)
+
super
+
+ setup_pry if should_pry?(argv)
end
+ def should_pry?(argv)
+ argv.flag?("pry", false) && !@dangerfile_path.empty? && validate_pry_available
+ end
+
+ def setup_pry
+ File.delete "_Dangerfile.tmp" if File.exist? "_Dangerfile.tmp"
+ FileUtils.cp @dangerfile_path, "_Dangerfile.tmp"
+ File.open("_Dangerfile.tmp", "a") do |f|
+ f.write("binding.pry; File.delete(\"_Dangerfile.tmp\")")
+ end
+ @dangerfile_path = "_Dangerfile.tmp"
+ end
+
+ def validate_pry_available
+ require "pry"
+ rescue LoadError
+ cork.warn "Pry was not found, and is required for 'danger local --pry'."
+ cork.print_warnings
+ abort
+ end
+
def self.options
[
["--use-merged-pr=[#id]", "The ID of an already merged PR inside your history to use as a reference for the local run."],
- ["--clear-http-cache", "Clear the local http cache before running Danger locally."]
+ ["--clear-http-cache", "Clear the local http cache before running Danger locally."],
+ ["--pry", "Drop into a Pry shell after evaluating the Dangerfile."]
].concat(super)
end
def validate!
super