Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codebuild): fails on using PR Events together with FILE_PATH filters in a FilterGroup #9725

Merged
merged 8 commits into from
Aug 17, 2020
3 changes: 0 additions & 3 deletions packages/@aws-cdk/aws-codebuild/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,6 @@ export class FilterGroup {
}

private addFilePathFilter(pattern: string, include: boolean): FilterGroup {
if (this.actions.size !== 1 || !this.actions.has(EventAction.PUSH)) {
throw new Error('A file path condition cannot be added if a Group contains any event action other than PUSH');
}
return this.addFilter(FILE_PATH_WEBHOOK_COND, pattern, include);
}

Expand Down
41 changes: 30 additions & 11 deletions packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,36 @@ export = {

test.done();
},
'with GitHub source including PULL_REQUEST_CREATED Event and FILE_PATH filter'(test: Test) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the below test instead? To show that it works now.

const stack = new cdk.Stack();

new codebuild.Project(stack, 'Project', {
source: codebuild.Source.gitHub({
owner: 'testowner',
repo: 'testrepo',
cloneDepth: 3,
webhook: true,
reportBuildStatus: false,
webhookFilters: [
codebuild.FilterGroup.inEventOf(codebuild.EventAction.PULL_REQUEST_CREATED).andFilePathIs('ReadMe.md'),
],
}),
});

expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', {
Triggers: {
Webhook: true,
FilterGroups: [
[
{ Type: 'EVENT', Pattern: 'PULL_REQUEST_CREATED' },
{ Type: 'FILE_PATH', Pattern: 'ReadMe.md' },
],
],
},
}));

test.done();
},
'with GitHubEnterprise source'(test: Test) {
const stack = new cdk.Stack();

Expand Down Expand Up @@ -1631,17 +1661,6 @@ export = {
test.done();
},

'cannot have file path conditions if the Group contains any action other than PUSH'(test: Test) {
const filterGroup = codebuild.FilterGroup.inEventOf(codebuild.EventAction.PULL_REQUEST_CREATED,
codebuild.EventAction.PUSH);

test.throws(() => {
filterGroup.andFilePathIsNot('.*\\.java');
}, /A file path condition cannot be added if a Group contains any event action other than PUSH/);

test.done();
},

Copy link
Contributor

@skinny85 skinny85 Aug 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'cannot have file path conditions if the Group contains any action other than PUSH'(test: Test) {
const filterGroup = codebuild.FilterGroup.inEventOf(codebuild.EventAction.PULL_REQUEST_CREATED,
codebuild.EventAction.PUSH);
test.throws(() => {
filterGroup.andFilePathIsNot('.*\\.java');
}, /A file path condition cannot be added if a Group contains any event action other than PUSH/);
test.done();
},
'can have FILE_PATH filters if the Group contains PUSH and PR_CREATED events'(test: Test) {
codebuild.FilterGroup.inEventOf(
codebuild.EventAction.PULL_REQUEST_CREATED,
codebuild.EventAction.PUSH)
.andFilePathIsNot('.*\\.java');
test.done();
},

'BitBucket sources do not support the PULL_REQUEST_REOPENED event action'(test: Test) {
const stack = new cdk.Stack();

Expand Down