Class: Bcnd::CI

Inherits:
Object
  • Object
show all
Defined in:
lib/bcnd/ci.rb

Constant Summary collapse

DEFAULT_CONFIG =
{
  "mainline_branch" => "master",
  "mainline_environment" => "staging",
  "stable_branch" => "production",
  "stable_environment" => "production"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCI

Returns a new instance of CI.



21
22
23
24
25
26
27
28
29
# File 'lib/bcnd/ci.rb', line 21

def initialize
  load_ci_environment
  load_stage_config
  self.quay_token = ENV['QUAY_TOKEN']
  self.github_token = ENV['GITHUB_TOKEN']
  self.mainline_heritage_token = ENV['MAINLINE_HERITAGE_TOKEN']
  self.stable_heritage_token = ENV['STABLE_HERITAGE_TOKEN']
  self.quay_repository = ENV['QUAY_REPOSITORY'] || self.repository
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



11
12
13
# File 'lib/bcnd/ci.rb', line 11

def branch
  @branch
end

#commitObject

Returns the value of attribute commit.



11
12
13
# File 'lib/bcnd/ci.rb', line 11

def commit
  @commit
end

#github_tokenObject

Returns the value of attribute github_token.



11
12
13
# File 'lib/bcnd/ci.rb', line 11

def github_token
  @github_token
end

#mainline_heritage_tokenObject

Returns the value of attribute mainline_heritage_token.



11
12
13
# File 'lib/bcnd/ci.rb', line 11

def mainline_heritage_token
  @mainline_heritage_token
end

#quay_repositoryObject

Returns the value of attribute quay_repository.



11
12
13
# File 'lib/bcnd/ci.rb', line 11

def quay_repository
  @quay_repository
end

#quay_tokenObject

Returns the value of attribute quay_token.



11
12
13
# File 'lib/bcnd/ci.rb', line 11

def quay_token
  @quay_token
end

#repositoryObject

Returns the value of attribute repository.



11
12
13
# File 'lib/bcnd/ci.rb', line 11

def repository
  @repository
end

#stable_heritage_tokenObject

Returns the value of attribute stable_heritage_token.



11
12
13
# File 'lib/bcnd/ci.rb', line 11

def stable_heritage_token
  @stable_heritage_token
end

#stage_configObject

Returns the value of attribute stage_config.



11
12
13
# File 'lib/bcnd/ci.rb', line 11

def stage_config
  @stage_config
end

Instance Method Details

#ci_serviceObject



40
41
42
43
44
45
46
47
48
# File 'lib/bcnd/ci.rb', line 40

def ci_service
  if ENV['TRAVIS']
    :travis
  elsif ENV['GITLAB_CI']
    :gitlab_ci
  else
    :unknown
  end
end

#deploy_environmentObject



65
66
67
# File 'lib/bcnd/ci.rb', line 65

def deploy_environment
  stage_config[deploy_stage][:environment]
end

#deploy_stageObject



58
59
60
61
62
63
# File 'lib/bcnd/ci.rb', line 58

def deploy_stage
  {
    mainline_branch => :mainline,
    stable_branch => :stable
  }[self.branch]
end

#mainline_branchObject



50
51
52
# File 'lib/bcnd/ci.rb', line 50

def mainline_branch
  stage_config[:mainline][:branch]
end

#pull_request?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/bcnd/ci.rb', line 31

def pull_request?
  case ci_service
  when :travis
    ENV['TRAVIS_PULL_REQUEST'] != 'false'
  when :gitlab_ci
    !!ENV['CI_MERGE_REQUEST_ID']
  end
end

#stable_branchObject



54
55
56
# File 'lib/bcnd/ci.rb', line 54

def stable_branch
  stage_config[:stable][:branch]
end