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.
-
#danger_id ⇒ Object
Returns the value of attribute danger_id.
-
#request_source ⇒ Object
Returns the value of attribute request_source.
-
#scm ⇒ Object
Returns the value of attribute scm.
-
#ui ⇒ Object
Returns the value of attribute ui.
Class Method Summary collapse
-
.danger_base_branch ⇒ String
Danger’s default base branch.
-
.danger_head_branch ⇒ String
Danger’s default head branch.
-
.local_ci_source(env) ⇒ Object
Finds a Danger::CI class based on the ENV.
-
.pr?(env) ⇒ Boolean
Uses the current Danger::CI subclass, and sees if it is a PR.
Instance Method Summary collapse
- #clean_up ⇒ Object
- #ensure_danger_branches_are_setup ⇒ Object
- #fill_environment_vars ⇒ Object
-
#initialize(env, ui = nil, danger_id = "danger") ⇒ EnvironmentManager
constructor
A new instance of EnvironmentManager.
- #meta_info_for_base ⇒ Object
- #meta_info_for_head ⇒ Object
- #pr? ⇒ Boolean
- #raise_error_for_no_request_source(env, ui) ⇒ Object
Constructor Details
#initialize(env, ui = nil, danger_id = "danger") ⇒ EnvironmentManager
Returns a new instance of EnvironmentManager.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/danger/danger_core/environment_manager.rb', line 30 def initialize(env, ui = nil, danger_id = "danger") ci_klass = self.class.local_ci_source(env) self.ci_source = ci_klass.new(env) self.ui = ui || Cork::Board.new(silent: false, verbose: false) self.danger_id = danger_id 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_error_for_no_request_source(env, self.ui) 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 |
#danger_id ⇒ Object
Returns the value of attribute danger_id.
6 7 8 |
# File 'lib/danger/danger_core/environment_manager.rb', line 6 def danger_id @danger_id 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 |
#ui ⇒ Object
Returns the value of attribute ui.
6 7 8 |
# File 'lib/danger/danger_core/environment_manager.rb', line 6 def ui @ui end |
Class Method Details
.danger_base_branch ⇒ String
Returns danger’s default base branch.
26 27 28 |
# File 'lib/danger/danger_core/environment_manager.rb', line 26 def self.danger_base_branch "danger_base".freeze end |
.danger_head_branch ⇒ String
Returns danger’s default head branch.
21 22 23 |
# File 'lib/danger/danger_core/environment_manager.rb', line 21 def self.danger_head_branch "danger_head".freeze end |
.local_ci_source(env) ⇒ Object
Finds a Danger::CI class based on the ENV
9 10 11 12 13 |
# File 'lib/danger/danger_core/environment_manager.rb', line 9 def self.local_ci_source(env) return Danger::LocalOnlyGitRepo if LocalOnlyGitRepo.validates_as_ci? 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
16 17 18 |
# File 'lib/danger/danger_core/environment_manager.rb', line 16 def self.pr?(env) local_ci_source(env).validates_as_pr?(env) end |
Instance Method Details
#clean_up ⇒ Object
64 65 66 67 68 |
# File 'lib/danger/danger_core/environment_manager.rb', line 64 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
58 59 60 61 62 |
# File 'lib/danger/danger_core/environment_manager.rb', line 58 def ensure_danger_branches_are_setup clean_up self.request_source.setup_danger_branches end |
#fill_environment_vars ⇒ Object
54 55 56 |
# File 'lib/danger/danger_core/environment_manager.rb', line 54 def fill_environment_vars request_source.fetch_details end |
#meta_info_for_base ⇒ Object
74 75 76 |
# File 'lib/danger/danger_core/environment_manager.rb', line 74 def scm.exec("--no-pager log #{EnvironmentManager.danger_base_branch} -n1") end |
#meta_info_for_head ⇒ Object
70 71 72 |
# File 'lib/danger/danger_core/environment_manager.rb', line 70 def scm.exec("--no-pager log #{EnvironmentManager.danger_head_branch} -n1") end |
#pr? ⇒ Boolean
50 51 52 |
# File 'lib/danger/danger_core/environment_manager.rb', line 50 def pr? self.ci_source != nil end |
#raise_error_for_no_request_source(env, ui) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/danger/danger_core/environment_manager.rb', line 78 def raise_error_for_no_request_source(env, ui) title, subtitle = extract_title_and_subtitle_from_source(ci_source.repo_url) subtitle += travis_note if env["TRAVIS_SECURE_ENV_VARS"] == "true" (ui, env, title, subtitle) exit(1) end |