Class: Danger::EnvironmentManager

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/danger_core/environment_manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ EnvironmentManager

Returns a new instance of EnvironmentManager.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/danger/danger_core/environment_manager.rb', line 18

def initialize(env)
  ci_klass = self.class.local_ci_source(env)
  self.ci_source = ci_klass.new(env)

  RequestSources::RequestSource.available_request_sources.each do |klass|
    next unless self.ci_source.supports?(klass)

    request_source = klass.new(self.ci_source, env)
    next unless request_source.validates_as_ci?
    next unless request_source.validates_as_api_source?
    self.request_source = request_source
  end

  raise "Could not find a Request Source for #{ci_klass}".red unless self.request_source
  self.scm = self.request_source.scm
end

Instance Attribute Details

#ci_sourceObject

Returns the value of attribute ci_source


6
7
8
# File 'lib/danger/danger_core/environment_manager.rb', line 6

def ci_source
  @ci_source
end

#request_sourceObject

Returns the value of attribute request_source


6
7
8
# File 'lib/danger/danger_core/environment_manager.rb', line 6

def request_source
  @request_source
end

#scmObject

Returns the value of attribute scm


6
7
8
# File 'lib/danger/danger_core/environment_manager.rb', line 6

def scm
  @scm
end

Class Method Details

.danger_base_branchObject


67
68
69
# File 'lib/danger/danger_core/environment_manager.rb', line 67

def self.danger_base_branch
  "danger_base"
end

.danger_head_branchObject


63
64
65
# File 'lib/danger/danger_core/environment_manager.rb', line 63

def self.danger_head_branch
  "danger_head"
end

.local_ci_source(env) ⇒ Object

Finds a Danger::CI class based on the ENV


9
10
11
# File 'lib/danger/danger_core/environment_manager.rb', line 9

def self.local_ci_source(env)
  CI.available_ci_sources.find { |ci| ci.validates_as_ci? env }
end

.pr?(env) ⇒ Boolean

Uses the current Danger::CI subclass, and sees if it is a PR

Returns:

  • (Boolean)

14
15
16
# File 'lib/danger/danger_core/environment_manager.rb', line 14

def self.pr?(env)
  local_ci_source(env).validates_as_pr?(env)
end

Instance Method Details

#clean_upObject


49
50
51
52
53
# File 'lib/danger/danger_core/environment_manager.rb', line 49

def clean_up
  [EnvironmentManager.danger_base_branch, EnvironmentManager.danger_head_branch].each do |branch|
    scm.exec("branch -D #{branch}") unless scm.exec("rev-parse --quiet --verify #{branch}").empty?
  end
end

#ensure_danger_branches_are_setupObject


43
44
45
46
47
# File 'lib/danger/danger_core/environment_manager.rb', line 43

def ensure_danger_branches_are_setup
  clean_up

  self.request_source.setup_danger_branches
end

#fill_environment_varsObject


39
40
41
# File 'lib/danger/danger_core/environment_manager.rb', line 39

def fill_environment_vars
  request_source.fetch_details
end

#meta_info_for_baseObject


55
56
57
# File 'lib/danger/danger_core/environment_manager.rb', line 55

def meta_info_for_base
  scm.exec("--no-pager log #{EnvironmentManager.danger_base_branch} -n1")
end

#meta_info_for_headObject


59
60
61
# File 'lib/danger/danger_core/environment_manager.rb', line 59

def meta_info_for_head
  scm.exec("--no-pager log #{EnvironmentManager.danger_head_branch} -n1")
end

#pr?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/danger/danger_core/environment_manager.rb', line 35

def pr?
  self.ci_source != nil
end