Skip to content

Commit

Permalink
CDK allows empty pushFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Feb 10, 2024
1 parent 95d1712 commit a716855
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
9 changes: 5 additions & 4 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 Down Expand Up @@ -147,7 +147,8 @@ export class Trigger {
});

gitConfiguration = {
push,
// set to undefined if 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 a716855

Please sign in to comment.