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

pipelines: unable to reference GitLab repositories nested under a group with CodePipelieneSource.connection #27504

Closed
akrantz01 opened this issue Oct 11, 2023 · 7 comments · Fixed by #29631 · 4 remaining pull requests
Closed

pipelines: unable to reference GitLab repositories nested under a group with CodePipelieneSource.connection #27504

akrantz01 opened this issue Oct 11, 2023 · 7 comments · Fixed by #29631 · 4 remaining pull requests
Assignees
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1

Comments

@akrantz01
Copy link

Describe the bug

GitLab repositories that are nested under at least one group cannot be directly with CodePipelineSource.connection as it limits repositories to the form <owner>/<repo>. GitLab includes the group names in the repository string, falling outside this format (i.e. owner/group1/group2/groupN/repo).

Expected Behavior

I expect the pipeline to synthesize successfully when sourcing from a CodePipelineSource.connection that references a GitLab repository nested under multiple groups.

Current Behavior

The following error is thrown:

Error: CodeStar repository name should be a resolved string like '<owner>/<repo>', got 'owner/group1/group2/repo'

This error is from aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.ts line 429.

Reproduction Steps

import * as cdk from 'aws-cdk-lib';
import { CodePipeline, CodePipelineSource, ShellStep } from 'aws-cdk-lib/pipelines';
import { Construct } from 'constructs';

class DummyStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
  }
}

class DummyApplication extends cdk.Stage {
  constructor(scope: Construct, id: string, props?: cdk.StageProps) {
    super(scope, id, props);

    new DummyStack(this, 'Dummy');
  }
}

export class PipelineStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const pipeline = new CodePipeline(this, 'Pipeline', {
      synth: new ShellStep("Synthesize", {
        input: CodePipelineSource.connection('owner/group/repo', 'main', {
          connectionArn: 'arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41',
        }),
        commands: [
          'npm ci',
          'npm run build',
          'npx cdk synth',
        ],
      }),
    });

    pipeline.addStage(new DummyApplication(this, 'DummyApp'));
  }
}

Possible Solution

--- a/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.ts
+++ b/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.ts
@@ -425,11 +425,11 @@ class CodeStarConnectionSource extends CodePipelineSource 
{
     super(repoString);
 
     const parts = repoString.split('/');
-    if (Token.isUnresolved(repoString) || parts.length !== 2) {
+    if (Token.isUnresolved(repoString) || parts.length < 2) {
       throw new Error(`CodeStar repository name should be a resolved string like '<owner>/<repo>', got '${repoString}'`);
     }
     this.owner = parts[0];
-    this.repo = parts[1];
+    this.repo = parts.slice(1).join('/');
     this.configurePrimaryOutput(new FileSet('Source', this));
   }

Additional Information/Context

No response

CDK CLI Version

2.100.0 (build e1b5c77)

Framework Version

No response

Node.js Version

v18.17.1

OS

Ubuntu 20.04.6 LTS

Language

Python

Language Version

Python 3.8.10

Other information

As a workaround until this is fixed, you can manually re-implement CodeStarConnectionSource to include the above changes and instantiate directly.

@akrantz01 akrantz01 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 11, 2023
@github-actions github-actions bot added the @aws-cdk/pipelines CDK Pipelines library label Oct 11, 2023
@peterwoodworth peterwoodworth added p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Oct 12, 2023
@peterwoodworth
Copy link
Contributor

Thanks for the request, this bug makes sense and it should be an easy fix

@peterwoodworth peterwoodworth added the good first issue Related to contributions. See CONTRIBUTING.md label Oct 12, 2023
@Abhinav-CHD
Copy link

I'd like to work on this issue

@jgilewski-siili
Copy link

I was happy reading this https://aws.amazon.com/about-aws/whats-new/2023/08/aws-codepipeline-supports-gitlab/ and was struggling with CDK finally finding this issue. Hope it will be fixed soon :)

@airmonitor
Copy link

Hey.

CDK Team how it's going with fixing that issue?

@kirtishrinkhala kirtishrinkhala self-assigned this Mar 8, 2024
@sebastian-kucharzyk-tcl

This sounds like an amazing feature for GitLab users (including myself). I'd love to see that happen, especially that there already was a MR for that.

@afrankevych
Copy link

Is there any update on this?

@mergify mergify bot closed this as completed in #29631 Apr 1, 2024
mergify bot pushed a commit that referenced this issue Apr 1, 2024
### Issue # (if applicable)

Closes #27504 

### Reason for this change

The current validation of `repoString` in constructor of `CodeStarConnectionSource` does not support nested repository that can appear in GitLab.

### Description of changes

The validation is fixed to accept nested repository.

### Description of how you validated changes

I added unit tests and confirmed all tests passed.

### 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*
Copy link

github-actions bot commented Apr 1, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment