Skip to content

Commit a0b62b9

Browse files
committed
add validations
1 parent 55fa3ec commit a0b62b9

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ export class Trigger {
166166
}
167167

168168
pushFilter?.forEach(filter => {
169+
if ((filter.tagsExcludes || filter.tagsIncludes) && (filter.branchesExcludes || filter.branchesIncludes)) {
170+
throw new Error(`cannot specify both tags and branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
171+
}
172+
if (!filter.branchesExcludes && !filter.branchesIncludes && (filter.filePathsExcludes || filter.filePathsIncludes)) {
173+
throw new Error(`cannot specify filePaths without branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
174+
}
169175
if (filter.tagsExcludes && filter.tagsExcludes.length > 8) {
170176
throw new Error(`maximum length of tagsExcludes in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.tagsExcludes.length}`);
171177
}

packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,40 @@ describe('triggers', () => {
566566
}).toThrow(/maximum length of filePathsIncludes in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
567567
});
568568

569-
// TODO: implements and add tests
570-
// 1. tags and branches (with filePaths) are mutually exclusive
571-
// 2. filePaths without branches is not allowed
569+
test('throw if tags and branches are specified', () => {
570+
expect(() => {
571+
new codepipeline.Pipeline(stack, 'Pipeline', {
572+
pipelineType: codepipeline.PipelineType.V2,
573+
triggers: [{
574+
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
575+
gitConfiguration: {
576+
sourceAction,
577+
pushFilter: [{
578+
tagsExcludes: ['exclude1', 'exclude2'],
579+
branchesExcludes: ['exclude1', 'exclude2'],
580+
}],
581+
},
582+
}],
583+
});
584+
}).toThrow(/cannot specify both tags and branches in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
585+
});
586+
587+
test('throw if filePaths without branches is specified', () => {
588+
expect(() => {
589+
new codepipeline.Pipeline(stack, 'Pipeline', {
590+
pipelineType: codepipeline.PipelineType.V2,
591+
triggers: [{
592+
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
593+
gitConfiguration: {
594+
sourceAction,
595+
pushFilter: [{
596+
filePathsExcludes: ['exclude1', 'exclude2'],
597+
}],
598+
},
599+
}],
600+
});
601+
}).toThrow(/cannot specify filePaths without branches in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
602+
});
572603

573604
test('empty pushFilter for trigger is set to undefined', () => {
574605
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', {

0 commit comments

Comments
 (0)