Skip to content

Commit

Permalink
feat(codebuild): add missing types for webhook filters (#30064)
Browse files Browse the repository at this point in the history
  • Loading branch information
msambol authored Jun 11, 2024
1 parent 665396f commit 1d93094
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/aws-cdk-lib/aws-codebuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
```
Expand Down
23 changes: 23 additions & 0 deletions packages/aws-cdk-lib/aws-codebuild/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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 {
Expand Down
23 changes: 22 additions & 1 deletion packages/aws-cdk-lib/aws-codebuild/test/codebuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
}),
});
Expand Down Expand Up @@ -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' },
],
],
},
});
Expand Down Expand Up @@ -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'),
Expand All @@ -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.*' },
],
[
Expand Down

0 comments on commit 1d93094

Please sign in to comment.