From 1d93094318ddb216ddaea344f92eaf830fb8b3ef Mon Sep 17 00:00:00 2001 From: Michael Sambol Date: Tue, 11 Jun 2024 10:29:51 -0500 Subject: [PATCH] feat(codebuild): add missing types for webhook filters (#30064) The full list is found [here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-webhookfilter.html#cfn-codebuild-project-webhookfilter-type). Closes #30062. --- packages/aws-cdk-lib/aws-codebuild/README.md | 3 +++ .../aws-cdk-lib/aws-codebuild/lib/source.ts | 23 +++++++++++++++++++ .../aws-codebuild/test/codebuild.test.ts | 23 ++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-codebuild/README.md b/packages/aws-cdk-lib/aws-codebuild/README.md index 85d681a9c8acf..3dde80fa45528 100644 --- a/packages/aws-cdk-lib/aws-codebuild/README.md +++ b/packages/aws-cdk-lib/aws-codebuild/README.md @@ -69,6 +69,9 @@ const gitHubSource = codebuild.Source.gitHub({ .inEventOf(codebuild.EventAction.PUSH) .andBranchIs('main') .andCommitMessageIs('the commit message'), + codebuild.FilterGroup + .inEventOf(codebuild.EventAction.RELEASED) + .andBranchIs('main') ], // optional, by default all pushes and Pull Requests will trigger a build }); ``` diff --git a/packages/aws-cdk-lib/aws-codebuild/lib/source.ts b/packages/aws-cdk-lib/aws-codebuild/lib/source.ts index 42a231bdacd06..5e2250fdafe3e 100644 --- a/packages/aws-cdk-lib/aws-codebuild/lib/source.ts +++ b/packages/aws-cdk-lib/aws-codebuild/lib/source.ts @@ -178,6 +178,11 @@ export enum EventAction { */ PULL_REQUEST_UPDATED = 'PULL_REQUEST_UPDATED', + /** + * Closing a Pull Request. + */ + PULL_REQUEST_CLOSED = 'PULL_REQUEST_CLOSED', + /** * Merging a Pull Request. */ @@ -188,6 +193,24 @@ export enum EventAction { * Note that this event is only supported for GitHub and GitHubEnterprise sources. */ PULL_REQUEST_REOPENED = 'PULL_REQUEST_REOPENED', + + /** + * A release is created in the repository. + * Works with GitHub only. + */ + RELEASED = 'RELEASED', + + /** + * A prerelease is created in the repository. + * Works with GitHub only. + */ + PRERELEASED = 'PRERELEASED', + + /** + * A workflow job is queued in the repository. + * Works with GitHub only. + */ + WORKFLOW_JOB_QUEUED = 'WORKFLOW_JOB_QUEUED', } enum WebhookFilterTypes { diff --git a/packages/aws-cdk-lib/aws-codebuild/test/codebuild.test.ts b/packages/aws-cdk-lib/aws-codebuild/test/codebuild.test.ts index b9d2c4cb8de7c..3eb3ac3fe6894 100644 --- a/packages/aws-cdk-lib/aws-codebuild/test/codebuild.test.ts +++ b/packages/aws-cdk-lib/aws-codebuild/test/codebuild.test.ts @@ -567,6 +567,10 @@ describe('default properties', () => { webhookFilters: [ codebuild.FilterGroup.inEventOf(codebuild.EventAction.PUSH).andTagIsNot('stable'), codebuild.FilterGroup.inEventOf(codebuild.EventAction.PULL_REQUEST_REOPENED).andBaseBranchIs('main'), + codebuild.FilterGroup.inEventOf(codebuild.EventAction.RELEASED).andBaseBranchIs('main'), + codebuild.FilterGroup.inEventOf(codebuild.EventAction.PRERELEASED).andBaseBranchIs('main'), + codebuild.FilterGroup.inEventOf(codebuild.EventAction.WORKFLOW_JOB_QUEUED).andBaseBranchIs('main'), + codebuild.FilterGroup.inEventOf(codebuild.EventAction.PULL_REQUEST_CLOSED).andBaseBranchIs('main'), ], }), }); @@ -595,6 +599,22 @@ describe('default properties', () => { { Type: 'EVENT', Pattern: 'PULL_REQUEST_REOPENED' }, { Type: 'BASE_REF', Pattern: 'refs/heads/main' }, ], + [ + { Type: 'EVENT', Pattern: 'RELEASED' }, + { Type: 'BASE_REF', Pattern: 'refs/heads/main' }, + ], + [ + { Type: 'EVENT', Pattern: 'PRERELEASED' }, + { Type: 'BASE_REF', Pattern: 'refs/heads/main' }, + ], + [ + { Type: 'EVENT', Pattern: 'WORKFLOW_JOB_QUEUED' }, + { Type: 'BASE_REF', Pattern: 'refs/heads/main' }, + ], + [ + { Type: 'EVENT', Pattern: 'PULL_REQUEST_CLOSED' }, + { Type: 'BASE_REF', Pattern: 'refs/heads/main' }, + ], ], }, }); @@ -664,6 +684,7 @@ describe('default properties', () => { codebuild.EventAction.PULL_REQUEST_CREATED, codebuild.EventAction.PULL_REQUEST_UPDATED, codebuild.EventAction.PULL_REQUEST_MERGED, + codebuild.EventAction.PULL_REQUEST_CLOSED, ).andTagIs('v.*'), // duplicate event actions are fine codebuild.FilterGroup.inEventOf(codebuild.EventAction.PUSH, codebuild.EventAction.PUSH).andActorAccountIsNot('aws-cdk-dev'), @@ -685,7 +706,7 @@ describe('default properties', () => { Webhook: true, FilterGroups: [ [ - { Type: 'EVENT', Pattern: 'PULL_REQUEST_CREATED, PULL_REQUEST_UPDATED, PULL_REQUEST_MERGED' }, + { Type: 'EVENT', Pattern: 'PULL_REQUEST_CREATED, PULL_REQUEST_UPDATED, PULL_REQUEST_MERGED, PULL_REQUEST_CLOSED' }, { Type: 'HEAD_REF', Pattern: 'refs/tags/v.*' }, ], [