Class: Danger::EnvironmentManager
- Inherits:
-
Object
- Object
- Danger::EnvironmentManager
- Defined in:
- lib/danger/danger_core/environment_manager.rb
Instance Attribute Summary collapse
-
#ci_source ⇒ Object
Returns the value of attribute ci_source.
-
#request_source ⇒ Object
Returns the value of attribute request_source.
-
#scm ⇒ Object
Returns the value of attribute scm.
Class Method Summary collapse
Instance Method Summary collapse
- #clean_up ⇒ Object
- #ensure_danger_branches_are_setup ⇒ Object
- #fill_environment_vars ⇒ Object
-
#initialize(env) ⇒ EnvironmentManager
constructor
A new instance of EnvironmentManager.
- #meta_info_for_base ⇒ Object
- #meta_info_for_head ⇒ Object
- #pr? ⇒ Boolean
Constructor Details
#initialize(env) ⇒ EnvironmentManager
Returns a new instance of EnvironmentManager.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/danger/danger_core/environment_manager.rb', line 8 def initialize(env) CISource::CI.available_ci_sources.each do |klass| next unless klass.validates?(env) self.ci_source = klass.new(env) if self.ci_source.repo_slug and self.ci_source.pull_request_id break else self.ci_source = nil return nil end end raise "Could not find a valid pull request within the known CI sources".red unless self.ci_source 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? self.request_source = request_source end raise "Could not find a Request Source".red unless self.request_source self.scm = self.request_source.scm end |
Instance Attribute Details
#ci_source ⇒ Object
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_source ⇒ Object
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 |
#scm ⇒ Object
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_branch ⇒ Object
68 69 70 |
# File 'lib/danger/danger_core/environment_manager.rb', line 68 def self.danger_base_branch "danger_base" end |
.danger_head_branch ⇒ Object
64 65 66 |
# File 'lib/danger/danger_core/environment_manager.rb', line 64 def self.danger_head_branch "danger_head" end |
Instance Method Details
#clean_up ⇒ Object
50 51 52 53 54 |
# File 'lib/danger/danger_core/environment_manager.rb', line 50 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_setup ⇒ Object
44 45 46 47 48 |
# File 'lib/danger/danger_core/environment_manager.rb', line 44 def ensure_danger_branches_are_setup clean_up self.request_source.setup_danger_branches end |
#fill_environment_vars ⇒ Object
40 41 42 |
# File 'lib/danger/danger_core/environment_manager.rb', line 40 def fill_environment_vars request_source.fetch_details end |
#meta_info_for_base ⇒ Object
56 57 58 |
# File 'lib/danger/danger_core/environment_manager.rb', line 56 def scm.exec("--no-pager log #{EnvironmentManager.danger_base_branch} -n1") end |
#meta_info_for_head ⇒ Object
60 61 62 |
# File 'lib/danger/danger_core/environment_manager.rb', line 60 def scm.exec("--no-pager log #{EnvironmentManager.danger_head_branch} -n1") end |
#pr? ⇒ Boolean
36 37 38 |
# File 'lib/danger/danger_core/environment_manager.rb', line 36 def pr? self.ci_source != nil end |