lib/danger/commands/local.rb in danger-0.7.4 vs lib/danger/commands/local.rb in danger-0.8.0
- old
+ new
@@ -9,11 +9,11 @@
super
end
def self.options
[
- ['--use-merged-pr=[#id]', 'The ID of an alreadty merged PR inside your history to use as a reference for the local run.']
+ ['--use-merged-pr=[#id]', 'The ID of an already merged PR inside your history to use as a reference for the local run.']
].concat(super)
end
def validate!
super
@@ -24,12 +24,13 @@
def run
ENV["DANGER_USE_LOCAL_GIT"] = "YES"
ENV["LOCAL_GIT_PR_ID"] = @pr_num if @pr_num
- dm = Dangerfile.new
- dm.env = EnvironmentManager.new(ENV)
+ env = EnvironmentManager.new(ENV)
+ dm = Dangerfile.new(env)
+ dm.init_plugins
source = dm.env.ci_source
if source.nil? or source.repo_slug.empty?
puts "danger local failed because it only works with GitHub projects at the moment. Sorry.".red
exit 0
@@ -47,18 +48,26 @@
puts ""
# We can use tokenless here, as it's running on someone's computer
# and is IP locked, as opposed to on the CI.
gh.support_tokenless_auth = true
- gh.fetch_details
+ begin
+ gh.fetch_details
+ rescue Octokit::NotFound
+ puts "Local repository was not found on GitHub. If you're trying to test a private repository please provide a valid API token through " + "DANGER_GITHUB_API_TOKEN".yellow + " environment variable."
+ return
+ end
+
dm.env.request_source = gh
- dm.env.scm = GitRepo.new
-
- dm.env.ensure_danger_branches_are_setup
- dm.env.scm.diff_for_folder(".", from: dm.env.ci_source.base_commit, to: dm.env.ci_source.head_commit)
- dm.parse(Pathname.new(@dangerfile_path))
- dm.print_results
+ begin
+ dm.env.ensure_danger_branches_are_setup
+ dm.env.scm.diff_for_folder(".", from: dm.env.ci_source.base_commit, to: dm.env.ci_source.head_commit)
+ dm.parse(Pathname.new(@dangerfile_path))
+ dm.print_results
+ ensure
+ dm.env.clean_up
+ end
end
end
end