Class: CodeBuildNotifier::CurrentBuild
- Inherits:
-
Object
- Object
- CodeBuildNotifier::CurrentBuild
- Defined in:
- lib/codebuild-notifier/current_build.rb
Instance Attribute Summary collapse
-
#build_id ⇒ Object
readonly
Returns the value of attribute build_id.
-
#commit_hash ⇒ Object
readonly
Returns the value of attribute commit_hash.
-
#git_repo_url ⇒ Object
readonly
Returns the value of attribute git_repo_url.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#trigger ⇒ Object
readonly
Returns the value of attribute trigger.
Instance Method Summary collapse
- #for_pr? ⇒ Boolean
-
#initialize(build_id: ENV['CODEBUILD_BUILD_ID'], commit_hash: ENV['CODEBUILD_RESOLVED_SOURCE_VERSION'], git_repo: ENV['CODEBUILD_SOURCE_REPO_URL'], status_code: ENV['CODEBUILD_BUILD_SUCCEEDING'], trigger: ENV['CODEBUILD_WEBHOOK_TRIGGER']) ⇒ CurrentBuild
constructor
Default values are extracted from CODEBUILD_* ENV vars present in each CodeBuild # job container.
-
#launched_by_retry? ⇒ Boolean
If trigger is empty, this build was launched using the Retry command from the console or api.
- #project_code ⇒ Object
-
#source_id ⇒ Object
source_id, the primary key, is a composite of project_code and trigger.
- #status ⇒ Object
Constructor Details
#initialize(build_id: ENV['CODEBUILD_BUILD_ID'], commit_hash: ENV['CODEBUILD_RESOLVED_SOURCE_VERSION'], git_repo: ENV['CODEBUILD_SOURCE_REPO_URL'], status_code: ENV['CODEBUILD_BUILD_SUCCEEDING'], trigger: ENV['CODEBUILD_WEBHOOK_TRIGGER']) ⇒ CurrentBuild
Default values are extracted from CODEBUILD_* ENV vars present in each CodeBuild # job container.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/codebuild-notifier/current_build.rb', line 24 def initialize( build_id: ENV['CODEBUILD_BUILD_ID'], commit_hash: ENV['CODEBUILD_RESOLVED_SOURCE_VERSION'], git_repo: ENV['CODEBUILD_SOURCE_REPO_URL'], status_code: ENV['CODEBUILD_BUILD_SUCCEEDING'], trigger: ENV['CODEBUILD_WEBHOOK_TRIGGER'] ) @build_id = build_id @commit_hash = commit_hash # Handle repos specified with and without optional .git suffix. @git_repo_url = git_repo.to_s.gsub(/\.git\z/, '') @status_code = status_code @trigger = trigger end |
Instance Attribute Details
#build_id ⇒ Object (readonly)
Returns the value of attribute build_id.
20 21 22 |
# File 'lib/codebuild-notifier/current_build.rb', line 20 def build_id @build_id end |
#commit_hash ⇒ Object (readonly)
Returns the value of attribute commit_hash.
20 21 22 |
# File 'lib/codebuild-notifier/current_build.rb', line 20 def commit_hash @commit_hash end |
#git_repo_url ⇒ Object (readonly)
Returns the value of attribute git_repo_url.
20 21 22 |
# File 'lib/codebuild-notifier/current_build.rb', line 20 def git_repo_url @git_repo_url end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
20 21 22 |
# File 'lib/codebuild-notifier/current_build.rb', line 20 def status_code @status_code end |
#trigger ⇒ Object (readonly)
Returns the value of attribute trigger.
20 21 22 |
# File 'lib/codebuild-notifier/current_build.rb', line 20 def trigger @trigger end |
Instance Method Details
#for_pr? ⇒ Boolean
53 54 55 |
# File 'lib/codebuild-notifier/current_build.rb', line 53 def for_pr? %r{^pr/}.match?(trigger.to_s) end |
#launched_by_retry? ⇒ Boolean
If trigger is empty, this build was launched using the Retry command from the console or api.
49 50 51 |
# File 'lib/codebuild-notifier/current_build.rb', line 49 def launched_by_retry? trigger.to_s.empty? end |
#project_code ⇒ Object
43 44 45 |
# File 'lib/codebuild-notifier/current_build.rb', line 43 def project_code @project_code ||= build_id.split(':').first end |
#source_id ⇒ Object
source_id, the primary key, is a composite of project_code and trigger. e.g.:
my-app_ruby2-4:branch/master
my-app_ruby2-3:pr/4056
project_code forms part of the key to support having repos with multiple projects, for example, with different buildspec files for different ruby versions, or for rspec vs cucumber.
65 66 67 |
# File 'lib/codebuild-notifier/current_build.rb', line 65 def source_id "#{project_code}:#{trigger}" end |
#status ⇒ Object
39 40 41 |
# File 'lib/codebuild-notifier/current_build.rb', line 39 def status status_code.to_s == '1' ? 'SUCCEEDED' : 'FAILED' end |