Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pipelines): codeStar connection accepts nested repository #29631

Merged
merged 8 commits into from
Apr 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,32 @@ class CodeStarConnectionSource extends CodePipelineSource {
constructor(repoString: string, readonly branch: string, readonly props: ConnectionSourceOptions) {
super(repoString);

const parts = repoString.split('/');
if (Token.isUnresolved(repoString) || parts.length !== 2) {
throw new Error(`CodeStar repository name should be a resolved string like '<owner>/<repo>', got '${repoString}'`);
if (!this.isValidRepoString(repoString)) {
throw new Error(`CodeStar repository name should be a resolved string like '<owner>/<repo>' or '<owner>/<group>/<repo>', got '${repoString}'`);
yynakanoyy marked this conversation as resolved.
Show resolved Hide resolved
}

const parts = repoString.split('/');

this.owner = parts[0];
this.repo = parts[1];
this.repo = parts.slice(1).join('/');
this.configurePrimaryOutput(new FileSet('Source', this));
}

private isValidRepoString(repoString: string) {
if (Token.isUnresolved(repoString)) {
return false;
}

const parts = repoString.split('/');

if (parts.length < 2) {
aaythapa marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

// check if all element in parts is not empty
return parts.every(element => element !== '');
}

protected getAction(output: Artifact, actionName: string, runOrder: number, variablesNamespace?: string) {
return new cp_actions.CodeStarConnectionsSourceAction({
output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,47 @@ test('Dashes in repo names are removed from artifact names', () => {
});
});

test.each([
'owner/repo',
'owner/group1/group2/groupN/repo',
])('CodeStar connection honors all valid properties', (repoString) => {
const connectionArn = 'arn:aws:codestar-connections:us-east-1:123456789012:connection/12345678-abcd-12ab-34cdef5678gh';

new ModernTestGitHubNpmPipeline(pipelineStack, 'Pipeline', {
input: cdkp.CodePipelineSource.connection(repoString, 'main', {
connectionArn: connectionArn,
}),
});

Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
Stages: Match.arrayWith([{
Name: 'Source',
Actions: [
Match.objectLike({
Configuration: Match.objectLike({
FullRepositoryId: repoString,
BranchName: 'main',
ConnectionArn: connectionArn,
}),
Name: repoString.replace(/\//g, '_'),
}),
],
}]),
});
});

test.each([
'repo-only',
'owner//duplicatedDash/repo',
])('CodeStar connection does not accept ill-formatted identifiers', (repoString) => {
expect(() => {
new ModernTestGitHubNpmPipeline(pipelineStack, 'Pipeline', {
input: cdkp.CodePipelineSource.connection(repoString, 'main',
{ connectionArn: 'arn:aws:codestar-connections:us-east-1:123456789012:connection/12345678-abcd-12ab-34cdef5678gh' }),
});
}).toThrow(`CodeStar repository name should be a resolved string like \'<owner>/<repo>\' or \'<owner>/<group>/<repo>\', got \'${repoString}\'`);
});

test('artifact names are never longer than 128 characters', () => {
new ModernTestGitHubNpmPipeline(pipelineStack, 'Pipeline', {
input: cdkp.CodePipelineSource.gitHub('owner/' + 'my-repo'.repeat(100), 'main'),
Expand Down
Loading