From e6fcdd2a42927a8107de08300becf46c8a8d2f37 Mon Sep 17 00:00:00 2001 From: Sibiraj <20282546+sibiraj-s@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:09:11 +0530 Subject: [PATCH] feat: add support for AWS codebuild PR --- index.js | 13 +++++++++++-- test.js | 34 ++++++++++++++++++++++++++++++++++ vendors.json | 10 +++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 4790726..69611fa 100644 --- a/index.js +++ b/index.js @@ -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) { @@ -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] }) diff --git a/test.js b/test.js index abc5806..9cec9b6 100644 --- a/test.js +++ b/test.js @@ -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 diff --git a/vendors.json b/vendors.json index 6b65e3f..b0d43ac 100644 --- a/vendors.json +++ b/vendors.json @@ -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",