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): allow FILE_PATH webhook filter for BitBucket #13186

Merged
merged 3 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions packages/@aws-cdk/aws-codebuild/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export class FilterGroup {
* Create a new FilterGroup with an added condition:
* the push that is the source of the event must affect a file that matches the given pattern.
* Note that you can only use this method if this Group contains only the `PUSH` event action,
* and only for GitHub and GitHubEnterprise sources.
* and only for GitHub, Bitbucket and GitHubEnterprise sources.
*
* @param pattern a regular expression
*/
Expand All @@ -393,7 +393,7 @@ export class FilterGroup {
* Create a new FilterGroup with an added condition:
* the push that is the source of the event must not affect a file that matches the given pattern.
* Note that you can only use this method if this Group contains only the `PUSH` event action,
* and only for GitHub and GitHubEnterprise sources.
* and only for GitHub, Bitbucket and GitHubEnterprise sources.
*
* @param pattern a regular expression
*/
Expand Down Expand Up @@ -788,11 +788,6 @@ class BitBucketSource extends ThirdPartyGitSource {
throw new Error('BitBucket sources do not support the PULL_REQUEST_REOPENED webhook event action');
}

// they also don't support file path conditions
if (this.anyWebhookFilterContainsFilePathConditions()) {
throw new Error('BitBucket sources do not support file path conditions for webhook filters');
}

const superConfig = super.bind(_scope, _project);
return {
sourceProperty: {
Expand All @@ -809,12 +804,6 @@ class BitBucketSource extends ThirdPartyGitSource {
return fg._actions.findIndex(a => a === EventAction.PULL_REQUEST_REOPENED) !== -1;
}) !== -1;
}

private anyWebhookFilterContainsFilePathConditions() {
return this.webhookFilters.findIndex(fg => {
return fg._filters.findIndex(f => f.type === WebhookFilterTypes.FILE_PATH) !== -1;
}) !== -1;
}
}

function set2Array<T>(set: Set<T>): T[] {
Expand Down
18 changes: 8 additions & 10 deletions packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1801,19 +1801,17 @@ export = {
test.done();
},

'BitBucket sources do not support file path conditions'(test: Test) {
'BitBucket sources support file path conditions'(test: Test) {
const stack = new cdk.Stack();
const filterGroup = codebuild.FilterGroup.inEventOf(codebuild.EventAction.PUSH).andFilePathIs('.*');

test.throws(() => {
new codebuild.Project(stack, 'Project', {
source: codebuild.Source.bitBucket({
owner: 'owner',
repo: 'repo',
webhookFilters: [filterGroup],
}),
});
}, /BitBucket sources do not support file path conditions for webhook filters/);
new codebuild.Project(stack, 'Project', {
source: codebuild.Source.bitBucket({
owner: 'owner',
repo: 'repo',
webhookFilters: [filterGroup],
}),
});

test.done();
},
Expand Down