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

Verify source version before parsing PR #172

Merged
merged 1 commit into from
Mar 9, 2020
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/services/codebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ module.exports = {
return git.branch()
}
function detectPRNumber() {
if (process.env.CODEBUILD_WEBHOOK_HEAD_REF) {
if (
process.env.CODEBUILD_WEBHOOK_HEAD_REF &&
process.env.CODEBUILD_SOURCE_VERSION.startsWith('pr/')
) {
return process.env.CODEBUILD_SOURCE_VERSION.replace(/^pr\//, '')
}
return undefined
Expand Down
17 changes: 16 additions & 1 deletion test/services/codebuild.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('AWS CodeBuild Provider', function() {
})
})

it('Test build triggered via Github Webhook', function() {
it('Test PR build triggered via Github Webhook', function() {
process.env.CODEBUILD_WEBHOOK_HEAD_REF = 'refs/heads/master'
expect(codebuild.configuration()).toEqual({
service: 'codebuild',
Expand All @@ -68,6 +68,21 @@ describe('AWS CodeBuild Provider', function() {
})
})

it('Test non-PR build triggered via Github Webhook', function() {
process.env.CODEBUILD_WEBHOOK_HEAD_REF = 'refs/heads/master'
process.env.CODEBUILD_SOURCE_VERSION =
'39ec2418eca4c539d765574a1c68f3bd77e8c549'
expect(codebuild.configuration()).toEqual({
service: 'codebuild',
build: 'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969',
job: 'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969',
commit: '39ec2418eca4c539d765574a1c68f3bd77e8c549',
branch: 'master',
pr: undefined,
slug: 'my-org/my-project',
})
})

it('throws if slug cannot be detected', function() {
process.env.CODEBUILD_RESOLVED_SOURCE_VERSION =
'39ec2418eca4c539d765574a1c68f3bd77e8c549'
Expand Down