Skip to content

Commit

Permalink
feat: add support for AWS codebuild PR
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Nov 12, 2024
1 parent f92a09d commit e6fcdd2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ vendors.forEach(function (vendor) {
break
case 'object':
if ('env' in vendor.pr) {
// "pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" }
exports.isPR = vendor.pr.env in env && env[vendor.pr.env] !== vendor.pr.ne
if ('any' in vendor.pr) {
// "pr": { "env": "CODEBUILD_WEBHOOK_EVENT", "any": ["PULL_REQUEST_CREATED", "PULL_REQUEST_UPDATED"] }
exports.isPR = vendor.pr.any.some(function (key) {
return env[vendor.pr.env] === key
})
} else {
// "pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" }
exports.isPR = vendor.pr.env in env && env[vendor.pr.env] !== vendor.pr.ne
}
} else if ('any' in vendor.pr) {
// "pr": { "any": ["ghprbPullId", "CHANGE_ID"] }
exports.isPR = vendor.pr.any.some(function (key) {
Expand Down Expand Up @@ -79,11 +86,13 @@ function checkEnv (obj) {
return env[obj.env] && env[obj.env].includes(obj.includes)
// }
}

if ('any' in obj) {
return obj.any.some(function (k) {
return !!env[k]
})
}

return Object.keys(obj).every(function (k) {
return env[k] === obj[k]
})
Expand Down
34 changes: 34 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,40 @@ test('Earthly CI', function (t) {
t.end()
})

test('AWS Codebuild', function (t) {
process.env.CODEBUILD_BUILD_ARN = 'true'

clearModule('./')
const ci = require('./')

t.equal(ci.isCI, true)
t.equal(ci.name, 'AWS CodeBuild')
t.equal(ci.CODEBUILD, true)
assertVendorConstants('CODEBUILD', ci, t)

delete process.env.CODEBUILD_BUILD_ARN

t.end()
})

test('AWS Codebuild - PR', function (t) {
process.env.CODEBUILD_BUILD_ARN = 'true'
process.env.CODEBUILD_WEBHOOK_EVENT = 'PULL_REQUEST_CREATED'

clearModule('./')
const ci = require('./')

t.equal(ci.isCI, true)
t.equal(ci.isPR, true)
t.equal(ci.name, 'AWS CodeBuild')
t.equal(ci.CODEBUILD, true)
assertVendorConstants('CODEBUILD', ci, t)

delete process.env.CODEBUILD_BUILD_ARN

t.end()
})

function assertVendorConstants (expect, ci, t) {
ci._vendors.forEach(function (constant) {
const bool = constant === expect
Expand Down
10 changes: 9 additions & 1 deletion vendors.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
{
"name": "AWS CodeBuild",
"constant": "CODEBUILD",
"env": "CODEBUILD_BUILD_ARN"
"env": "CODEBUILD_BUILD_ARN",
"pr": {
"env": "CODEBUILD_WEBHOOK_EVENT",
"any": [
"PULL_REQUEST_CREATED",
"PULL_REQUEST_UPDATED",
"PULL_REQUEST_REOPENED"
]
}
},
{
"name": "Azure Pipelines",
Expand Down

0 comments on commit e6fcdd2

Please sign in to comment.