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

Commit

Permalink
Merge pull request #172 from RoboCafaz/bugfix/codebuild-pr-parser
Browse files Browse the repository at this point in the history
Verify source version before parsing PR
  • Loading branch information
eddiemoore authored Mar 9, 2020
2 parents 55d69cd + ef348ec commit eb8a527
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit eb8a527

Please sign in to comment.