Class: Danger::Local

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

Instance Attribute Summary

Attributes inherited from Runner

#cork

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Local

Returns a new instance of Local.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/danger/commands/local.rb', line 22

def initialize(argv)
  show_help = true if argv.arguments == ["-h"]

  @pr_num = argv.option("use-merged-pr")
  @clear_http_cache = argv.flag?("clear-http-cache", false)

  # Currently CLAide doesn't support short option like -h https://github.com/CocoaPods/CLAide/pull/60
  # when user pass in -h, mimic the behavior of passing in --help.
  argv = CLAide::ARGV.new ["--help"] if show_help

  super

  if argv.flag?("pry", false)
    @dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path, Local.command)
  end
end

Class Method Details

.optionsObject



14
15
16
17
18
19
20
# File 'lib/danger/commands/local.rb', line 14

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."],
    ["--pry", "Drop into a Pry shell after evaluating the Dangerfile."]
  ]
end

Instance Method Details

#runObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/danger/commands/local.rb', line 46

def run
  ENV["DANGER_USE_LOCAL_GIT"] = "YES"
  ENV["LOCAL_GIT_PR_ID"] = @pr_num if @pr_num

  configure_octokit(ENV["DANGER_TMPDIR"] || Dir.tmpdir)

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

  LocalSetup.new(dm, cork).setup(verbose: verbose) do
    dm.run(
      Danger::EnvironmentManager.danger_base_branch,
      Danger::EnvironmentManager.danger_head_branch,
      @dangerfile_path,
      nil,
      nil,
      nil
    )
  end
end

#validate!Object



39
40
41
42
43
44
# File 'lib/danger/commands/local.rb', line 39

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