Class: Danger::Local

Inherits:
Runner
  • Object
show all
Defined in:
lib/danger/commands/local.rb

Instance Method Summary collapse

Methods inherited from Runner

options, #post_results

Constructor Details

#initialize(argv) ⇒ Local

Returns a new instance of Local.



6
7
8
9
# File 'lib/danger/commands/local.rb', line 6

def initialize(argv)
  @dangerfile_path = "Dangerfile" if File.exist? "Dangerfile"
  super
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/danger/commands/local.rb', line 18

def run
  ENV["DANGER_USE_LOCAL_GIT"] = "YES"

  dm = Dangerfile.new
  dm.env = EnvironmentManager.new(ENV)

  source = dm.env.ci_source
  unless source.repo_slug
    puts "danger local".red " failed because it only works with GitHub projects at the moment. Sorry."
    exit 0
  end

  puts "Running your Dangerfile against this PR - https://github.com/#{source.repo_slug}/pulls/#{source.pull_request_id}"

  if verbose != true
    puts "Turning on --verbose"
    dm.verbose = true
  end

  puts ""

  gh = GitHub.new(dm.env.ci_source, ENV)
  # 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

  dm.env.request_source = gh

  dm.env.scm = GitRepo.new
  dm.env.scm.diff_for_folder(".", dm.env.ci_source.base_commit, dm.env.ci_source.head_commit)
  dm.parse Pathname.new(@dangerfile_path)
end

#validate!Object



11
12
13
14
15
16
# File 'lib/danger/commands/local.rb', line 11

def validate!
  super
  unless @dangerfile_path
    help! "Could not find a Dangerfile."
  end
end