Skip to content

Commit 1cac5a0

Browse files
authored
fix(codepipeline): allow both pullRequestFilter and pushFilter (#34267)
### Issue # (if applicable) Closes #34253 ### Reason for this change Validation too strict ### Description of changes - Allow both `pullRequestFilter` and `pushFilter` - Refactor integ for readability ### Description of how you validated changes Unit + Integ ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d4125a9 commit 1cac5a0

10 files changed

+137
-99
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-with-pipeline-triggers.js.snapshot/aws-cdk-codepipeline-with-pipeline-triggers.assets.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-with-pipeline-triggers.js.snapshot/aws-cdk-codepipeline-with-pipeline-triggers.template.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,34 @@
19871987
"Triggers": [
19881988
{
19891989
"GitConfiguration": {
1990+
"PullRequest": [
1991+
{
1992+
"Branches": {
1993+
"Excludes": [
1994+
"excludePR1",
1995+
"excludePR2"
1996+
],
1997+
"Includes": [
1998+
"includePR1",
1999+
"includePR2"
2000+
]
2001+
},
2002+
"Events": [
2003+
"OPEN",
2004+
"UPDATED"
2005+
],
2006+
"FilePaths": {
2007+
"Excludes": [
2008+
"/path/to/excludePR1",
2009+
"/path/to/excludePR2"
2010+
],
2011+
"Includes": [
2012+
"/path/to/includePR1",
2013+
"/path/to/includePR2"
2014+
]
2015+
}
2016+
}
2017+
],
19902018
"Push": [
19912019
{
19922020
"Branches": {

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-with-pipeline-triggers.js.snapshot/cdk.out

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-with-pipeline-triggers.js.snapshot/codepipelinewithpipelinetriggerstestDefaultTestDeployAssertE3F8DDE6.assets.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-with-pipeline-triggers.js.snapshot/codepipelinewithpipelinetriggerstestDefaultTestDeployAssertE3F8DDE6.template.json

Lines changed: 8 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-with-pipeline-triggers.js.snapshot/integ.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-with-pipeline-triggers.js.snapshot/manifest.json

Lines changed: 47 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-with-pipeline-triggers.ts

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ new codepipeline.Pipeline(stack, 'codepipeline-integ-trigger-test', {
156156
filePathsExcludes: ['/path/to/exclude1', '/path/to/exclude2'],
157157
filePathsIncludes: ['/path/to/include1', '/path/to/include2'],
158158
}],
159+
pullRequestFilter: [{
160+
branchesExcludes: ['excludePR1', 'excludePR2'],
161+
branchesIncludes: ['includePR1', 'includePR2'],
162+
filePathsExcludes: ['/path/to/excludePR1', '/path/to/excludePR2'],
163+
filePathsIncludes: ['/path/to/includePR1', '/path/to/includePR2'],
164+
events: [codepipeline.GitPullRequestEvent.OPEN, codepipeline.GitPullRequestEvent.UPDATED],
165+
}],
159166
},
160167
}],
161168
});
@@ -171,35 +178,40 @@ awsApiCall1.assertAtPath('pipeline.name', ExpectedResult.stringLikeRegexp('my-pi
171178
const awsApiCall2 = integrationTest.assertions.awsApiCall('CodePipeline', 'getPipeline', { name: 'my-pipeline2' });
172179
awsApiCall2.assertAtPath('pipeline.name', ExpectedResult.stringLikeRegexp('my-pipeline2'));
173180

174-
const awsApiCall3 = integrationTest.assertions.awsApiCall('CodePipeline', 'getPipeline', { name: 'codepipeline-integ-trigger-test' });
175-
awsApiCall3.assertAtPath('pipeline.name',
176-
ExpectedResult.stringLikeRegexp('codepipeline-integ-trigger-test'));
177-
awsApiCall3.assertAtPath('pipeline.stages.0.name',
178-
ExpectedResult.stringLikeRegexp('Source'));
179-
awsApiCall3.assertAtPath('pipeline.stages.1.name',
180-
ExpectedResult.stringLikeRegexp('Build'));
181-
awsApiCall3.assertAtPath('pipeline.triggers.0.providerType',
182-
ExpectedResult.stringLikeRegexp(codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION));
183-
awsApiCall3.assertAtPath('pipeline.triggers.0.gitConfiguration.sourceActionName',
184-
ExpectedResult.stringLikeRegexp('integ-action-name'));
185-
// Assert branch includes
186-
awsApiCall3.assertAtPath('pipeline.triggers.0.gitConfiguration.push.0.branches.includes.0',
187-
ExpectedResult.stringLikeRegexp('include1'));
188-
awsApiCall3.assertAtPath('pipeline.triggers.0.gitConfiguration.push.0.branches.includes.1',
189-
ExpectedResult.stringLikeRegexp('include2'));
190-
awsApiCall3.assertAtPath('pipeline.triggers.0.gitConfiguration.push.0.branches.excludes.0',
191-
ExpectedResult.stringLikeRegexp('exclude1'));
192-
awsApiCall3.assertAtPath('pipeline.triggers.0.gitConfiguration.push.0.branches.excludes.1',
193-
ExpectedResult.stringLikeRegexp('exclude2'));
194-
// Assert file path includes
195-
awsApiCall3.assertAtPath('pipeline.triggers.0.gitConfiguration.push.0.filePaths.includes.0',
196-
ExpectedResult.stringLikeRegexp('/path/to/include1'));
197-
awsApiCall3.assertAtPath('pipeline.triggers.0.gitConfiguration.push.0.filePaths.includes.1',
198-
ExpectedResult.stringLikeRegexp('/path/to/include2'));
199-
// Assert file path excludes
200-
awsApiCall3.assertAtPath('pipeline.triggers.0.gitConfiguration.push.0.filePaths.excludes.0',
201-
ExpectedResult.stringLikeRegexp('/path/to/exclude1'));
202-
awsApiCall3.assertAtPath('pipeline.triggers.0.gitConfiguration.push.0.filePaths.excludes.1',
203-
ExpectedResult.stringLikeRegexp('/path/to/exclude2'));
204-
205-
app.synth();
181+
integrationTest.assertions.awsApiCall('CodePipeline', 'getPipeline', {
182+
name: 'codepipeline-integ-trigger-test',
183+
}).expect(ExpectedResult.objectLike({
184+
pipeline: {
185+
name: 'codepipeline-integ-trigger-test',
186+
stages: [
187+
{ name: 'Source' },
188+
{ name: 'Build' },
189+
],
190+
triggers: [{
191+
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
192+
gitConfiguration: {
193+
sourceActionName: 'integ-action-name',
194+
push: [{
195+
branches: {
196+
includes: ['include1', 'include2'],
197+
excludes: ['exclude1', 'exclude2'],
198+
},
199+
filePaths: {
200+
includes: ['/path/to/include1', '/path/to/include2'],
201+
excludes: ['/path/to/exclude1', '/path/to/exclude2'],
202+
},
203+
}],
204+
pullRequest: [{
205+
branches: {
206+
includes: ['includePR1', 'includePR2'],
207+
excludes: ['excludePR1', 'excludePR2'],
208+
},
209+
filePaths: {
210+
includes: ['/path/to/includePR1', '/path/to/includePR2'],
211+
excludes: ['/path/to/excludePR1', '/path/to/excludePR2'],
212+
},
213+
}],
214+
},
215+
}],
216+
},
217+
}));

packages/aws-cdk-lib/aws-codepipeline/lib/private/validation.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ export function validateTriggers(gitConfiguration: GitConfiguration) {
8989
if (sourceAction.actionProperties.provider !== 'CodeStarSourceConnection') {
9090
throw new UnscopedValidationError(`provider for actionProperties in sourceAction with name '${sourceAction.actionProperties.actionName}' must be 'CodeStarSourceConnection', got '${sourceAction.actionProperties.provider}'`);
9191
}
92-
if (pushFilter?.length && pullRequestFilter?.length) {
93-
throw new UnscopedValidationError(`cannot specify both GitPushFilter and GitPullRequestFilter for the trigger with sourceAction with name '${sourceAction.actionProperties.actionName}'`);
94-
}
9592
if (!pushFilter?.length && !pullRequestFilter?.length) {
9693
throw new UnscopedValidationError(`must specify either GitPushFilter or GitPullRequestFilter for the trigger with sourceAction with name '${sourceAction.actionProperties.actionName}'`);
9794
}

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,32 +1008,6 @@ describe('triggers', () => {
10081008
}).toThrow(/length of GitPullRequestFilter for sourceAction with name 'CodeStarConnectionsSourceAction' must be less than or equal to 3, got 4/);
10091009
});
10101010

1011-
test('throw if both GitPushFilter and GitPullRequestFilter are specified', () => {
1012-
expect(() => {
1013-
new codepipeline.Pipeline(stack, 'Pipeline', {
1014-
pipelineType: codepipeline.PipelineType.V2,
1015-
triggers: [{
1016-
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
1017-
gitConfiguration: {
1018-
sourceAction,
1019-
pushFilter: [
1020-
{
1021-
tagsExcludes: ['exclude1'],
1022-
tagsIncludes: ['include1'],
1023-
},
1024-
],
1025-
pullRequestFilter: [
1026-
{
1027-
branchesExcludes: ['exclude1'],
1028-
branchesIncludes: ['include1'],
1029-
},
1030-
],
1031-
},
1032-
}],
1033-
});
1034-
}).toThrow(/cannot specify both GitPushFilter and GitPullRequestFilter for the trigger with sourceAction with name 'CodeStarConnectionsSourceAction'/);
1035-
});
1036-
10371011
test('throw if neither GitPushFilter nor GitPullRequestFilter are specified', () => {
10381012
expect(() => {
10391013
new codepipeline.Pipeline(stack, 'Pipeline', {

0 commit comments

Comments
 (0)