Skip to content

Commit

Permalink
add validations
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Feb 17, 2024
1 parent 55fa3ec commit a0b62b9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ export class Trigger {
}

pushFilter?.forEach(filter => {
if ((filter.tagsExcludes || filter.tagsIncludes) && (filter.branchesExcludes || filter.branchesIncludes)) {
throw new Error(`cannot specify both tags and branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
}
if (!filter.branchesExcludes && !filter.branchesIncludes && (filter.filePathsExcludes || filter.filePathsIncludes)) {
throw new Error(`cannot specify filePaths without branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
}
if (filter.tagsExcludes && filter.tagsExcludes.length > 8) {
throw new Error(`maximum length of tagsExcludes in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.tagsExcludes.length}`);
}
Expand Down
37 changes: 34 additions & 3 deletions packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,40 @@ describe('triggers', () => {
}).toThrow(/maximum length of filePathsIncludes in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
});

// TODO: implements and add tests
// 1. tags and branches (with filePaths) are mutually exclusive
// 2. filePaths without branches is not allowed
test('throw if tags and branches are specified', () => {
expect(() => {
new codepipeline.Pipeline(stack, 'Pipeline', {
pipelineType: codepipeline.PipelineType.V2,
triggers: [{
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
gitConfiguration: {
sourceAction,
pushFilter: [{
tagsExcludes: ['exclude1', 'exclude2'],
branchesExcludes: ['exclude1', 'exclude2'],
}],
},
}],
});
}).toThrow(/cannot specify both tags and branches in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
});

test('throw if filePaths without branches is specified', () => {
expect(() => {
new codepipeline.Pipeline(stack, 'Pipeline', {
pipelineType: codepipeline.PipelineType.V2,
triggers: [{
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
gitConfiguration: {
sourceAction,
pushFilter: [{
filePathsExcludes: ['exclude1', 'exclude2'],
}],
},
}],
});
}).toThrow(/cannot specify filePaths without branches in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
});

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

0 comments on commit a0b62b9

Please sign in to comment.