class Danger::LocalSetup

Attributes

cork[R]
dm[R]

Public Class Methods

new(dangerfile, cork) click to toggle source
# File lib/danger/commands/local_helpers/local_setup.rb, line 5
def initialize(dangerfile, cork)
  @dm = dangerfile
  @cork = cork
end

Public Instance Methods

setup(verbose: false) { || ... } click to toggle source
# File lib/danger/commands/local_helpers/local_setup.rb, line 10
def setup(verbose: false)
  source = dm.env.ci_source
  if source.nil? or source.repo_slug.empty?
    cork.puts "danger local failed because it only works with GitHub and Bitbucket server projects at the moment. Sorry.".red
    exit 0
  end
  gh = dm.env.request_source
  # We can use tokenless here, as it's running on someone's computer
  # and is IP locked, as opposed to on the CI. Only for Github PRs
  if gh.instance_of? Danger::RequestSources::GitHub
    gh.support_tokenless_auth = true
  end

  if gh.instance_of? Danger::RequestSources::BitbucketServer
    cork.puts "Running your Dangerfile against this PR - #{gh.host}/projects/#{source.repo_slug.split('/').first}/repos/#{source.repo_slug.split('/').last}/pull-requests/#{source.pull_request_id}"
  elsif gh.instance_of? Danger::RequestSources::VSTS
    cork.puts "Running your Dangerfile against this PR - #{gh.client.pr_api_endpoint}"
  else
    cork.puts "Running your Dangerfile against this PR - https://#{gh.host}/#{source.repo_slug}/pull/#{source.pull_request_id}"
  end

  unless verbose
    cork.puts "Turning on --verbose"
    dm.verbose = true
  end

  cork.puts

  begin
    gh.fetch_details
  rescue Octokit::NotFound
    cork.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

  yield
end