1
1
import events = require( '@aws-cdk/aws-events' ) ;
2
- import { CfnOutput , Construct , IResource , Resource } from '@aws-cdk/cdk' ;
2
+ import { CfnOutput , Construct , IConstruct , IResource , Resource , Stack } from '@aws-cdk/cdk' ;
3
3
import { CfnRepository } from './codecommit.generated' ;
4
4
5
5
export interface IRepository extends IResource {
@@ -244,14 +244,12 @@ export class Repository extends RepositoryBase {
244
244
public static fromRepositoryArn ( scope : Construct , id : string , repositoryArn : string ) : IRepository {
245
245
const stack = scope . node . stack ;
246
246
const repositoryName = stack . parseArn ( repositoryArn ) . resource ;
247
- const makeCloneUrl = ( protocol : 'https' | 'ssh' ) =>
248
- `${ protocol } ://git-codecommit.${ stack . region } .${ stack . urlSuffix } /v1/repos/${ repositoryName } ` ;
249
247
250
248
class Import extends RepositoryBase {
251
249
public readonly repositoryArn = repositoryArn ;
252
250
public readonly repositoryName = repositoryName ;
253
- public readonly repositoryCloneUrlHttp = makeCloneUrl ( 'https' ) ;
254
- public readonly repositoryCloneUrlSsh = makeCloneUrl ( 'ssh' ) ;
251
+ public readonly repositoryCloneUrlHttp = Repository . makeCloneUrl ( stack , repositoryName , 'https' ) ;
252
+ public readonly repositoryCloneUrlSsh = Repository . makeCloneUrl ( stack , repositoryName , 'ssh' ) ;
255
253
public export ( ) {
256
254
return {
257
255
repositoryArn : this . repositoryArn ,
@@ -263,6 +261,37 @@ export class Repository extends RepositoryBase {
263
261
return new Import ( scope , id ) ;
264
262
}
265
263
264
+ public static fromRepositoryName ( scope : Construct , id : string , repositoryName : string ) : IRepository {
265
+ const stack = scope . node . stack ;
266
+
267
+ class Import extends RepositoryBase {
268
+ public repositoryName = repositoryName ;
269
+ public repositoryArn = Repository . arnForLocalRepository ( repositoryName , scope ) ;
270
+ public readonly repositoryCloneUrlHttp = Repository . makeCloneUrl ( stack , repositoryName , 'https' ) ;
271
+ public readonly repositoryCloneUrlSsh = Repository . makeCloneUrl ( stack , repositoryName , 'ssh' ) ;
272
+
273
+ public export ( ) {
274
+ return {
275
+ repositoryArn : this . repositoryArn ,
276
+ repositoryName : this . repositoryName ,
277
+ } ;
278
+ }
279
+ }
280
+
281
+ return new Import ( scope , id ) ;
282
+ }
283
+
284
+ private static makeCloneUrl ( stack : Stack , repositoryName : string , protocol : 'https' | 'ssh' ) {
285
+ return `${ protocol } ://git-codecommit.${ stack . region } .${ stack . urlSuffix } /v1/repos/${ repositoryName } ` ;
286
+ }
287
+
288
+ private static arnForLocalRepository ( repositoryName : string , scope : IConstruct ) : string {
289
+ return scope . node . stack . formatArn ( {
290
+ service : 'codecommit' ,
291
+ resource : repositoryName ,
292
+ } ) ;
293
+ }
294
+
266
295
private readonly repository : CfnRepository ;
267
296
private readonly triggers = new Array < CfnRepository . RepositoryTriggerProperty > ( ) ;
268
297
0 commit comments