Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Feb 22, 2024
1 parent 8cd7ef1 commit 2ebda40
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,24 @@ export class Trigger {
const pushFilter = this.props.gitConfiguration.pushFilter;

const push: CfnPipeline.GitPushFilterProperty[] | undefined = pushFilter?.map(filter => {
const tags: CfnPipeline.GitTagFilterCriteriaProperty | undefined = {
// 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,
};
const branches: CfnPipeline.GitBranchFilterCriteriaProperty | undefined = {
// set to undefined if empty array because CloudFormation does not accept empty array
excludes: filter.branchesExcludes?.length ? filter.branchesExcludes : undefined,
includes: filter.branchesIncludes?.length ? filter.branchesIncludes : undefined,
};
const filePaths: CfnPipeline.GitFilePathFilterCriteriaProperty | undefined = {
// set to undefined if empty array because CloudFormation does not accept empty array
excludes: filter.filePathsExcludes?.length ? filter.filePathsExcludes : undefined,
includes: filter.filePathsIncludes?.length ? filter.filePathsIncludes : undefined,
};
const tags: CfnPipeline.GitTagFilterCriteriaProperty | undefined =
filter.tagsExcludes?.length || filter.tagsIncludes?.length ? {
// 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,
} : undefined;
const branches: CfnPipeline.GitBranchFilterCriteriaProperty | undefined =
filter.branchesExcludes?.length || filter.branchesIncludes?.length ? {
// set to undefined if empty array because CloudFormation does not accept empty array
excludes: filter.branchesExcludes?.length ? filter.branchesExcludes : undefined,
includes: filter.branchesIncludes?.length ? filter.branchesIncludes : undefined,
} : undefined;
const filePaths: CfnPipeline.GitFilePathFilterCriteriaProperty | undefined =
filter.filePathsExcludes?.length || filter.filePathsIncludes?.length ? {
// set to undefined if empty array because CloudFormation does not accept empty array
excludes: filter.filePathsExcludes?.length ? filter.filePathsExcludes : undefined,
includes: filter.filePathsIncludes?.length ? filter.filePathsIncludes : undefined,
} : undefined;
return { tags, branches, filePaths };
});

Expand Down
19 changes: 19 additions & 0 deletions packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ describe('triggers', () => {
Excludes: ['exclude1', 'exclude2'],
Includes: ['include1', 'include2'],
},
Branches: Match.absent(),
FilePaths: Match.absent(),
}],
},
ProviderType: 'CodeStarSourceConnection',
Expand Down Expand Up @@ -85,10 +87,12 @@ describe('triggers', () => {
GitConfiguration: {
SourceActionName: 'CodeStarConnectionsSourceAction',
Push: [{
Tags: Match.absent(),
Branches: {
Excludes: ['exclude1', 'exclude2'],
Includes: ['include1', 'include2'],
},
FilePaths: Match.absent(),
}],
},
ProviderType: 'CodeStarSourceConnection',
Expand Down Expand Up @@ -121,6 +125,7 @@ describe('triggers', () => {
GitConfiguration: {
SourceActionName: 'CodeStarConnectionsSourceAction',
Push: [{
Tags: Match.absent(),
Branches: {
Excludes: ['exclude1', 'exclude2'],
Includes: ['include1', 'include2'],
Expand Down Expand Up @@ -185,6 +190,8 @@ describe('triggers', () => {
Excludes: ['exclude1', 'exclude2'],
Includes: ['include1', 'include2'],
},
Branches: Match.absent(),
FilePaths: Match.absent(),
}],
},
ProviderType: 'CodeStarSourceConnection',
Expand Down Expand Up @@ -231,6 +238,8 @@ describe('triggers', () => {
Excludes: ['exclude1', 'exclude2'],
Includes: ['include1', 'include2'],
},
Branches: Match.absent(),
FilePaths: Match.absent(),
}],
},
ProviderType: 'CodeStarSourceConnection',
Expand Down Expand Up @@ -265,6 +274,8 @@ describe('triggers', () => {
Excludes: Match.absent(),
Includes: ['include1', 'include2'],
},
Branches: Match.absent(),
FilePaths: Match.absent(),
}],
},
ProviderType: 'CodeStarSourceConnection',
Expand Down Expand Up @@ -299,6 +310,8 @@ describe('triggers', () => {
Excludes: ['excluded1', 'excluded2'],
Includes: Match.absent(),
},
Branches: Match.absent(),
FilePaths: Match.absent(),
}],
},
ProviderType: 'CodeStarSourceConnection',
Expand Down Expand Up @@ -329,10 +342,12 @@ describe('triggers', () => {
GitConfiguration: {
SourceActionName: 'CodeStarConnectionsSourceAction',
Push: [{
Tags: Match.absent(),
Branches: {
Excludes: Match.absent(),
Includes: ['include1', 'include2'],
},
FilePaths: Match.absent(),
}],
},
ProviderType: 'CodeStarSourceConnection',
Expand Down Expand Up @@ -363,10 +378,12 @@ describe('triggers', () => {
GitConfiguration: {
SourceActionName: 'CodeStarConnectionsSourceAction',
Push: [{
Tags: Match.absent(),
Branches: {
Excludes: ['excluded1', 'excluded2'],
Includes: Match.absent(),
},
FilePaths: Match.absent(),
}],
},
ProviderType: 'CodeStarSourceConnection',
Expand Down Expand Up @@ -399,6 +416,7 @@ describe('triggers', () => {
GitConfiguration: {
SourceActionName: 'CodeStarConnectionsSourceAction',
Push: [{
Tags: Match.absent(),
Branches: {
Excludes: ['exclude1', 'exclude2'],
Includes: ['include1', 'include2'],
Expand Down Expand Up @@ -439,6 +457,7 @@ describe('triggers', () => {
GitConfiguration: {
SourceActionName: 'CodeStarConnectionsSourceAction',
Push: [{
Tags: Match.absent(),
Branches: {
Excludes: ['exclude1', 'exclude2'],
Includes: ['include1', 'include2'],
Expand Down

0 comments on commit 2ebda40

Please sign in to comment.