Skip to content

Commit

Permalink
Allow use of a RepositoryRef when creating a CodeCommitSoureAction (#758
Browse files Browse the repository at this point in the history
)

When trying to use an imported CodeCommit repository (e.g. from a separate stack), one needs to
be able to create the source action using a `RepositoryRef` and not a `Repository`. In order for this
to work, the repository clone URLs needed to be made available on the `RepositoryRef` class.
  • Loading branch information
RomainMuller authored Sep 25, 2018
1 parent 6d2b531 commit f4078a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class NoSource extends BuildSource {
* CodeCommit Source definition for a CodeBuild project
*/
export class CodeCommitSource extends BuildSource {
constructor(private readonly repo: codecommit.Repository) {
constructor(private readonly repo: codecommit.RepositoryRef) {
super();
}

Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-codecommit/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export abstract class RepositoryRef extends cdk.Construct {

/** The human-visible name of this Repository. */
public abstract readonly repositoryName: string;
/** The HTTP clone URL */
public abstract readonly repositoryCloneUrlHttp: string;
/** The SSH clone URL */
public abstract readonly repositoryCloneUrlSsh: string;

/**
* Exports this Repository. Allows the same Repository to be used in 2 different Stacks.
Expand Down Expand Up @@ -182,6 +186,23 @@ class ImportedRepositoryRef extends RepositoryRef {
});
this.repositoryName = props.repositoryName;
}

public get repositoryCloneUrlHttp() {
return this.repositoryCloneUrl('https');
}

public get repositoryCloneUrlSsh() {
return this.repositoryCloneUrl('ssh');
}

private repositoryCloneUrl(protocol: 'https' | 'ssh'): string {
return new cdk.FnConcat(`${protocol}://git-codecommit.`,
new cdk.AwsRegion(),
'.',
new cdk.AwsURLSuffix(),
'/v1/repos/',
this.repositoryName).toString();
}
}

export interface RepositoryProps {
Expand Down

0 comments on commit f4078a2

Please sign in to comment.