Skip to content

Commit 2818bfa

Browse files
committed
add CloneRepository class with fromCodeCommit() support
1 parent b1a44f1 commit 2818bfa

File tree

4 files changed

+31
-34
lines changed

4 files changed

+31
-34
lines changed

packages/@aws-cdk/aws-cloud9/lib/environment.ts

+24-26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as codecommit from '@aws-cdk/aws-codecommit';
12
import * as ec2 from '@aws-cdk/aws-ec2';
23
import * as cdk from '@aws-cdk/core';
34
import { CfnEnvironmentEC2 } from '../lib/cloud9.generated';
@@ -20,7 +21,6 @@ export interface IEc2Environment extends cdk.IResource {
2021
* @attribute environmentE2Arn
2122
*/
2223
readonly ec2EnvironmentArn: string;
23-
2424
}
2525

2626
/**
@@ -67,38 +67,21 @@ export interface Ec2EnvironmentProps {
6767
*
6868
* @default - do not clone any repository
6969
*/
70-
readonly clonedRepositories?: Cloud9Repository[];
70+
// readonly clonedRepositories?: Cloud9Repository[];
71+
readonly clonedRepositories?: CloneRepositoryConfig[];
7172
}
7273

7374
/**
74-
* Repository provider
75+
* The configuration for repository cloning
7576
*/
76-
export enum Cloud9RepositoryProvider {
77+
export interface CloneRepositoryConfig {
7778
/**
78-
* AWS CodeCommit
79+
* The URL of the git repository
7980
*/
80-
AWS_CODECOMMIT
81-
}
81+
readonly repositoryUrl: string;
8282

83-
/**
84-
* The interface of the codecommit repository for Cloud9 environment
85-
*/
86-
export interface Cloud9Repository {
8783
/**
88-
* Repository provider
89-
* @default AWS_CODECOMMIT
90-
*/
91-
readonly provider?: Cloud9RepositoryProvider;
92-
93-
/**
94-
* Repository URL
95-
*/
96-
readonly url: string;
97-
98-
/**
99-
* The path within the development environment's default file system location to clone the AWS CodeCommit
100-
* repository into. For example, `/REPOSITORY_NAME` would clone the repository into the
101-
* `/home/USER_NAME/environment/REPOSITORY_NAME` directory in the environment.
84+
* The target path of the cloud9 environment to clone the repository to
10285
*/
10386
readonly clonePath: string;
10487
}
@@ -167,7 +150,7 @@ export class Ec2Environment extends cdk.Resource implements IEc2Environment {
167150
instanceType: props.instanceType?.toString() ?? ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO).toString(),
168151
subnetId: this.vpc.selectSubnets(vpcSubnets).subnetIds[0],
169152
repositories: props.clonedRepositories ? props.clonedRepositories.map(r => ({
170-
repositoryUrl: r.url,
153+
repositoryUrl: r.repositoryUrl,
171154
pathComponent: r.clonePath,
172155
})) : undefined,
173156
});
@@ -177,3 +160,18 @@ export class Ec2Environment extends cdk.Resource implements IEc2Environment {
177160
this.ideUrl = `https://${this.stack.region}.console.aws.amazon.com/cloud9/ide/${this.environmentId}`;
178161
}
179162
}
163+
164+
/**
165+
* The class with static methods generating `CloneRepositoryConfig` for different repository providers
166+
*/
167+
export class CloneRepository {
168+
/**
169+
* import repository to cloud9 environment from AWS CodeCommit
170+
*/
171+
public static fromCodeCommit(repository: codecommit.IRepository, path: string): CloneRepositoryConfig {
172+
return {
173+
repositoryUrl: repository.repositoryCloneUrlHttp,
174+
clonePath: path,
175+
};
176+
}
177+
}

packages/@aws-cdk/aws-cloud9/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@
7272
},
7373
"dependencies": {
7474
"@aws-cdk/core": "0.0.0",
75+
"@aws-cdk/aws-codecommit": "0.0.0",
7576
"@aws-cdk/aws-ec2": "0.0.0",
7677
"constructs": "^3.0.2"
7778
},
7879
"homepage": "https://github.com/aws/aws-cdk",
7980
"peerDependencies": {
8081
"@aws-cdk/core": "0.0.0",
82+
"@aws-cdk/aws-codecommit": "0.0.0",
8183
"@aws-cdk/aws-ec2": "0.0.0",
8284
"constructs": "^3.0.2"
8385
},

packages/@aws-cdk/aws-cloud9/test/cloud9.environment.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ test('throw error when subnetSelection not specified and the provided VPC has no
7171

7272
test('can use CodeCommit repositories', () => {
7373
// WHEN
74+
const repo = codecommit.Repository.fromRepositoryName(stack, 'Repo', 'foo');
75+
7476
new cloud9.Ec2Environment(stack, 'C9Env', {
7577
vpc,
7678
clonedRepositories: [
77-
{
78-
url: codecommit.Repository.fromRepositoryName(stack, 'Repo', 'foo').repositoryCloneUrlHttp,
79-
clonePath: '/foo',
80-
},
79+
cloud9.CloneRepository.fromCodeCommit(repo, '/foo'),
8180
],
8281
});
8382
// THEN

packages/@aws-cdk/aws-cloud9/test/integ.cloud9.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ export class Cloud9Env extends cdk.Stack {
2020
// create a cloud9 ec2 environment in a new VPC
2121
const c9env = new cloud9.Ec2Environment(this, 'C9Env', {
2222
vpc,
23+
// clone repositories into the environment
2324
clonedRepositories: [
24-
{
25-
url: repo.repositoryCloneUrlHttp,
26-
clonePath: '/foo',
27-
},
25+
cloud9.CloneRepository.fromCodeCommit(repo, '/foo'),
2826
],
2927
});
3028
new cdk.CfnOutput(this, 'URL', { value: c9env.ideUrl });

0 commit comments

Comments
 (0)