Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Fix value of params[:pr] when useing CodeBuild #102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/codecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ def build_params(ci)
params[:commit] = ENV['CODEBUILD_RESOLVED_SOURCE_VERSION']
params[:job] = ENV['CODEBUILD_BUILD_ID']
params[:slug] = ENV['CODEBUILD_SOURCE_REPO_URL'].match(/.*github.com\/(?<slug>.*).git/)['slug']
params[:pr] = ENV['CODEBUILD_SOURCE_VERSION'].match(/pr\/(?<pr>.*)/)['pr'] if ENV['CODEBUILD_SOURCE_VERSION']
params[:pr] = if ENV['CODEBUILD_SOURCE_VERSION']
matched = ENV['CODEBUILD_SOURCE_VERSION'].match(%r{pr/(?<pr>.*)})
matched.nil? ? ENV['CODEBUILD_SOURCE_VERSION'] : matched['pr']
end
when CODESHIP
# https://www.codeship.io/documentation/continuous-integration/set-environment-variables/
params[:service] = 'codeship'
Expand Down
21 changes: 21 additions & 0 deletions test/test_codecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,27 @@ def test_codebuild
assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
end

def test_codebuild_source_version_is_other_than_pr_number
ENV['CODEBUILD_CI'] = 'true'
ENV['CODEBUILD_BUILD_ID'] = 'codebuild-project:458dq3q8-7354-4513-8702-ea7b9c81efb3'
ENV['CODEBUILD_RESOLVED_SOURCE_VERSION'] = 'd653b934ed59c1a785cc1cc79d08c9aaa4eba73b'
ENV['CODEBUILD_WEBHOOK_HEAD_REF'] = 'refs/heads/master'
ENV['CODEBUILD_SOURCE_VERSION'] = 'git-commit-hash-12345'
ENV['CODEBUILD_SOURCE_REPO_URL'] = 'https://github.com/owner/repo.git'
ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'

result = upload

assert_equal('codebuild', result['params'][:service])
assert_equal('d653b934ed59c1a785cc1cc79d08c9aaa4eba73b', result['params'][:commit])
assert_equal('codebuild-project:458dq3q8-7354-4513-8702-ea7b9c81efb3', result['params'][:build])
assert_equal('git-commit-hash-12345', result['params'][:pr])
assert_equal('owner/repo', result['params'][:slug])
assert_equal('master', result['params'][:branch])
assert_equal('git-commit-hash-12345', result['params'][:pr])
assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
end

def test_filenames_are_shortened_correctly
ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'

Expand Down