Class: Danger::EnvironmentManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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
# File 'lib/danger/environment_manager.rb', line 8

def initialize(env)
  CISource.constants.each do |symb|
    c = CISource.const_get(symb)
    next unless c.kind_of?(Class)
    next unless c.validates?(env)

    self.ci_source = c.new(env)
    if self.ci_source.repo_slug and self.ci_source.pull_request_id
      break
    else
      puts "Not a Pull Request - skipping `danger` run"
      self.ci_source = nil
      return nil
    end
  end

  raise "Could not find a CI source".red unless self.ci_source

  # only GitHub for now, open for PRs adding more!
  self.request_source = GitHub.new(self.ci_source, ENV)
end

Instance Attribute Details

#ci_sourceObject

Returns the value of attribute ci_source.



6
7
8
# File 'lib/danger/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/environment_manager.rb', line 6

def request_source
  @request_source
end

#scmObject

Returns the value of attribute scm.



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

def scm
  @scm
end

Instance Method Details

#clean_upObject



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

def clean_up
  [danger_base_branch, danger_base_branch].each do |branch|
    scm.exec "branch -d #{branch}"
  end
end

#danger_base_branchObject



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

def danger_base_branch
  "danger_base"
end

#danger_head_branchObject



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

def danger_head_branch
  "danger_head"
end

#ensure_danger_branches_are_setupObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/danger/environment_manager.rb', line 36

def ensure_danger_branches_are_setup
  # As this currently just works with GitHub, we can use a github specific feature here:
  pull_id = ci_source.pull_request_id
  test_branch = request_source.base_commit

  # Next, we want to ensure that we have a version of the current branch that at a know location
  scm.exec "branch #{danger_base_branch} #{test_branch}"

  # OK, so we want to ensure that we have a known head branch, this will always represent
  # the head ( e.g. the most recent commit that will be merged. )
  scm.exec "fetch origin +refs/pull/#{pull_id}/merge:#{danger_head_branch}"
end

#fill_environment_varsObject



30
31
32
33
34
# File 'lib/danger/environment_manager.rb', line 30

def fill_environment_vars
  request_source.fetch_details

  self.scm = GitRepo.new # For now
end

#meta_info_for_baseObject



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

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

#meta_info_for_headObject



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

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