Skip to content

Commit

Permalink
CDK allows empty pushFilter
Browse files Browse the repository at this point in the history
comments
  • Loading branch information
go-to-k committed Feb 10, 2024
1 parent 95d1712 commit 94ee0e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
11 changes: 6 additions & 5 deletions packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface GitConfiguration {
*
* Git tags is the only supported event type.
*
* The length must be between 1 and 3.
* The length must be less than or equal to 3.
*
* @default - no filter.
*/
Expand Down Expand Up @@ -111,8 +111,8 @@ export class Trigger {
}

const pushFilter = this.props.gitConfiguration.pushFilter;
if (pushFilter !== undefined && (pushFilter.length < 1 || pushFilter.length > 3)) {
throw new Error(`length of pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' must be between 1 and 3, got ${pushFilter.length}`);
if (pushFilter !== undefined && pushFilter.length > 3) {
throw new Error(`length of pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' must be less than or equal to 3, got ${pushFilter.length}`);
}

pushFilter?.forEach(filter => {
Expand All @@ -139,15 +139,16 @@ export class Trigger {

const push: CfnPipeline.GitPushFilterProperty[] | undefined = pushFilter?.map(filter => {
const tags: CfnPipeline.GitTagFilterCriteriaProperty | undefined = {
// set to undefined if empty array
// set to undefined if empty array because CloudFormation does not accept empty array
excludes: filter.tagsExcludes?.length ? filter.tagsExcludes : undefined,
includes: filter.tagsIncludes?.length ? filter.tagsIncludes : undefined,
};
return { tags };
});

gitConfiguration = {
push,
// set to undefined if empty array because CloudFormation does not accept empty array
push: push?.length ? push : undefined,
sourceActionName: sourceAction.actionProperties.actionName,
};
}
Expand Down
39 changes: 25 additions & 14 deletions packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,30 @@ describe('triggers', () => {
}).toThrow(/maximum length of tagsIncludes for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
});

test('throw if length of pushFilter is less than 1', () => {
expect(() => {
new codepipeline.Pipeline(stack, 'Pipeline', {
pipelineType: codepipeline.PipelineType.V2,
triggers: [{
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
gitConfiguration: {
sourceAction,
pushFilter: [],
},
}],
});
}).toThrow(/length of pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' must be between 1 and 3, got 0/);
test('empty pushFilter for trigger is set to undefined', () => {
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', {
pipelineType: codepipeline.PipelineType.V2,
triggers: [{
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
gitConfiguration: {
sourceAction,
pushFilter: [],
},
}],
});

testPipelineSetup(pipeline, [sourceAction], [buildAction]);

Template.fromStack(stack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
PipelineType: 'V2',
Triggers: [{
GitConfiguration: {
SourceActionName: 'CodeStarConnectionsSourceAction',
Push: Match.absent(),
},
ProviderType: 'CodeStarSourceConnection',
}],
});
});

test('throw if length of pushFilter is greater than 3', () => {
Expand Down Expand Up @@ -312,7 +323,7 @@ describe('triggers', () => {
},
}],
});
}).toThrow(/length of pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' must be between 1 and 3, got 4/);;
}).toThrow(/length of pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' must be less than or equal to 3, got 4/);;
});

test('throw if provider of sourceAction is not \'CodeStarSourceConnection\'', () => {
Expand Down

0 comments on commit 94ee0e8

Please sign in to comment.