Class: CodeBuildNotifier::CurrentBuild
- Inherits:
-
Object
- Object
- CodeBuildNotifier::CurrentBuild
- Defined in:
- lib/codebuild-notifier/current_build.rb
Instance Attribute Summary collapse
-
#author_email ⇒ Object
readonly
attrs from git info.
-
#author_name ⇒ Object
readonly
attrs from git info.
-
#build_id ⇒ Object
readonly
Returns the value of attribute build_id.
-
#commit_hash ⇒ Object
readonly
Returns the value of attribute commit_hash.
-
#commit_message_subject ⇒ Object
readonly
attrs from git info.
-
#committer_email ⇒ Object
readonly
attrs from git info.
-
#committer_name ⇒ Object
readonly
attrs from git info.
-
#git_repo_url ⇒ Object
readonly
Returns the value of attribute git_repo_url.
-
#previous_build ⇒ Object
Returns the value of attribute previous_build.
-
#short_hash ⇒ Object
readonly
attrs from git info.
-
#source_version ⇒ Object
readonly
Returns the value of attribute source_version.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#trigger ⇒ Object
readonly
Returns the value of attribute trigger.
Instance Method Summary collapse
-
#branch_name ⇒ Object
If launched via retry, the webhook head ref env var is blank, but if the previous build for this branch has been located, the branch_name of that build is the same as for this build.
- #for_pr? ⇒ Boolean
- #history_fields ⇒ Object
-
#initialize(build_id: ENV['CODEBUILD_BUILD_ID'], commit_hash: ENV['CODEBUILD_RESOLVED_SOURCE_VERSION'], git_repo: ENV['CODEBUILD_SOURCE_REPO_URL'], head_ref: ENV['CODEBUILD_WEBHOOK_HEAD_REF'], start_time: ENV['CODEBUILD_START_TIME'], status_code: ENV['CODEBUILD_BUILD_SUCCEEDING'], source_version: ENV['CODEBUILD_SOURCE_VERSION'], 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.
- #source_ref ⇒ Object
- #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'], head_ref: ENV['CODEBUILD_WEBHOOK_HEAD_REF'], start_time: ENV['CODEBUILD_START_TIME'], status_code: ENV['CODEBUILD_BUILD_SUCCEEDING'], source_version: ENV['CODEBUILD_SOURCE_VERSION'], trigger: ENV['CODEBUILD_WEBHOOK_TRIGGER']) ⇒ CurrentBuild
Default values are extracted from CODEBUILD_* ENV vars present in each CodeBuild # job container.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/codebuild-notifier/current_build.rb', line 30 def initialize( build_id: ENV['CODEBUILD_BUILD_ID'], commit_hash: ENV['CODEBUILD_RESOLVED_SOURCE_VERSION'], git_repo: ENV['CODEBUILD_SOURCE_REPO_URL'], head_ref: ENV['CODEBUILD_WEBHOOK_HEAD_REF'], start_time: ENV['CODEBUILD_START_TIME'], status_code: ENV['CODEBUILD_BUILD_SUCCEEDING'], source_version: ENV['CODEBUILD_SOURCE_VERSION'], 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/, '') @head_ref = head_ref @source_version = source_version @start_time = start_time || (Time.now.to_f * 1_000).to_i @status_code = status_code @trigger = trigger @short_hash, @author_name, @author_email, @committer_name, @committer_email, @commit_message_subject = git_info end |
Instance Attribute Details
#author_email ⇒ Object (readonly)
attrs from git info
25 26 27 |
# File 'lib/codebuild-notifier/current_build.rb', line 25 def @author_email end |
#author_name ⇒ Object (readonly)
attrs from git info
25 26 27 |
# File 'lib/codebuild-notifier/current_build.rb', line 25 def @author_name end |
#build_id ⇒ Object (readonly)
Returns the value of attribute build_id.
21 22 23 |
# File 'lib/codebuild-notifier/current_build.rb', line 21 def build_id @build_id end |
#commit_hash ⇒ Object (readonly)
Returns the value of attribute commit_hash.
21 22 23 |
# File 'lib/codebuild-notifier/current_build.rb', line 21 def commit_hash @commit_hash end |
#commit_message_subject ⇒ Object (readonly)
attrs from git info
25 26 27 |
# File 'lib/codebuild-notifier/current_build.rb', line 25 def @commit_message_subject end |
#committer_email ⇒ Object (readonly)
attrs from git info
25 26 27 |
# File 'lib/codebuild-notifier/current_build.rb', line 25 def committer_email @committer_email end |
#committer_name ⇒ Object (readonly)
attrs from git info
25 26 27 |
# File 'lib/codebuild-notifier/current_build.rb', line 25 def committer_name @committer_name end |
#git_repo_url ⇒ Object (readonly)
Returns the value of attribute git_repo_url.
21 22 23 |
# File 'lib/codebuild-notifier/current_build.rb', line 21 def git_repo_url @git_repo_url end |
#previous_build ⇒ Object
Returns the value of attribute previous_build.
20 21 22 |
# File 'lib/codebuild-notifier/current_build.rb', line 20 def previous_build @previous_build end |
#short_hash ⇒ Object (readonly)
attrs from git info
25 26 27 |
# File 'lib/codebuild-notifier/current_build.rb', line 25 def short_hash @short_hash end |
#source_version ⇒ Object (readonly)
Returns the value of attribute source_version.
21 22 23 |
# File 'lib/codebuild-notifier/current_build.rb', line 21 def source_version @source_version end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
21 22 23 |
# File 'lib/codebuild-notifier/current_build.rb', line 21 def start_time @start_time end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
21 22 23 |
# File 'lib/codebuild-notifier/current_build.rb', line 21 def status_code @status_code end |
#trigger ⇒ Object (readonly)
Returns the value of attribute trigger.
21 22 23 |
# File 'lib/codebuild-notifier/current_build.rb', line 21 def trigger @trigger end |
Instance Method Details
#branch_name ⇒ Object
If launched via retry, the webhook head ref env var is blank, but if the previous build for this branch has been located, the branch_name of that build is the same as for this build
58 59 60 61 62 63 64 |
# File 'lib/codebuild-notifier/current_build.rb', line 58 def branch_name if launched_by_retry? previous_build&.branch_name else @head_ref.to_s.gsub(%r{^refs/heads/}, '') end end |
#for_pr? ⇒ Boolean
80 81 82 |
# File 'lib/codebuild-notifier/current_build.rb', line 80 def for_pr? %r{^pr/}.match?(source_version.to_s) end |
#history_fields ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/codebuild-notifier/current_build.rb', line 114 def history_fields { author_email: , author_name: , build_id: build_id, commit_hash: commit_hash, commit_subject: , committer_email: committer_email, committer_name: committer_name, git_repo_url: git_repo_url, project_code: project_code, start_time: start_time, status: status } end |
#launched_by_retry? ⇒ Boolean
If trigger is empty, this build was launched using the Retry command from the console or api.
76 77 78 |
# File 'lib/codebuild-notifier/current_build.rb', line 76 def launched_by_retry? trigger.to_s.empty? end |
#project_code ⇒ Object
70 71 72 |
# File 'lib/codebuild-notifier/current_build.rb', line 70 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.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/codebuild-notifier/current_build.rb', line 92 def source_id # If launched via retry, trigger is blank, but if the previous # build for this branch has been located, the source_id of that # build is the same as for this build if launched_by_retry? previous_build&.source_id else "#{project_code}:#{trigger}" end end |
#source_ref ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/codebuild-notifier/current_build.rb', line 103 def source_ref # If launched via retry, trigger is blank, but if the previous # build for this branch has been located, the source_ref of that # build is the same as for this build if launched_by_retry? previous_build&.source_ref else trigger end end |
#status ⇒ Object
66 67 68 |
# File 'lib/codebuild-notifier/current_build.rb', line 66 def status status_code.to_s == '1' ? 'SUCCEEDED' : 'FAILED' end |