@@ -344,8 +344,8 @@ export class Parser {
344
344
345
345
static async downloadIncludeFile ( cwd : string , project : string , ref : string , file : string , gitRemoteDomain : string ) : Promise < void > {
346
346
const time = process . hrtime ( ) ;
347
- fs . ensureDirSync ( `${ cwd } /.gitlab-ci-local/includes/${ project } /${ ref } /` ) ;
348
- await Utils . spawn ( `git archive --remote=git@${ gitRemoteDomain } :${ project } .git ${ ref } ${ file } | tar -xC .gitlab-ci-local/includes/${ project } /${ ref } /` , cwd ) ;
347
+ fs . ensureDirSync ( `${ cwd } /.gitlab-ci-local/includes/${ gitRemoteDomain } / ${ project } /${ ref } /` ) ;
348
+ await Utils . spawn ( `git archive --remote=git@${ gitRemoteDomain } :${ project } .git ${ ref } ${ file } | tar -xC .gitlab-ci-local/includes/${ gitRemoteDomain } / ${ project } /${ ref } /` , cwd ) ;
349
349
const endTime = process . hrtime ( time ) ;
350
350
const remoteUrl = `${ gitRemoteDomain } /${ project } /${ file } ` ;
351
351
process . stdout . write ( `${ cyan ( 'downloaded' ) } ${ magentaBright ( remoteUrl ) } in ${ magenta ( prettyHrtime ( endTime ) ) } \n` ) ;
@@ -376,11 +376,16 @@ export class Parser {
376
376
377
377
// Find files to fetch from remote and place in .gitlab-ci-local/includes
378
378
for ( const value of gitlabData [ "include" ] || [ ] ) {
379
- if ( ! value [ "file" ] || tabCompletionPhase ) {
379
+ if ( tabCompletionPhase ) {
380
380
continue ;
381
381
}
382
+ if ( value [ "file" ] ) {
383
+ promises . push ( Parser . downloadIncludeFile ( cwd , value [ "project" ] , value [ "ref" ] || "master" , value [ "file" ] , gitRemote . domain ) ) ;
384
+ } else if ( value [ "template" ] ) {
385
+ const { project, ref, file, domain} = Parser . parseTemplateInclude ( value [ 'template' ] ) ;
386
+ promises . push ( Parser . downloadIncludeFile ( cwd , project , ref , file , domain ) ) ;
387
+ }
382
388
383
- promises . push ( Parser . downloadIncludeFile ( cwd , value [ "project" ] , value [ "ref" ] || "master" , value [ "file" ] , gitRemote . domain ) ) ;
384
389
}
385
390
386
391
await Promise . all ( promises ) ;
@@ -390,7 +395,11 @@ export class Parser {
390
395
const localDoc = await Parser . loadYaml ( `${ cwd } /${ value . local } ` ) ;
391
396
includeDatas = includeDatas . concat ( await Parser . prepareIncludes ( localDoc , cwd , gitRemote , tabCompletionPhase ) ) ;
392
397
} else if ( value [ "file" ] ) {
393
- const fileDoc = await Parser . loadYaml ( `${ cwd } /.gitlab-ci-local/includes/${ value [ "project" ] } /${ value [ "ref" ] || "master" } /${ value [ "file" ] } ` ) ;
398
+ const fileDoc = await Parser . loadYaml ( `${ cwd } /.gitlab-ci-local/includes/${ gitRemote . domain } /${ value [ "project" ] } /${ value [ "ref" ] || "master" } /${ value [ "file" ] } ` ) ;
399
+ includeDatas = includeDatas . concat ( await Parser . prepareIncludes ( fileDoc , cwd , gitRemote , tabCompletionPhase ) ) ;
400
+ } else if ( value [ 'template' ] ) {
401
+ const { project, ref, file, domain} = Parser . parseTemplateInclude ( value [ 'template' ] ) ;
402
+ const fileDoc = await Parser . loadYaml ( `${ cwd } /.gitlab-ci-local/includes/${ domain } /${ project } /${ ref } /${ file } ` ) ;
394
403
includeDatas = includeDatas . concat ( await Parser . prepareIncludes ( fileDoc , cwd , gitRemote , tabCompletionPhase ) ) ;
395
404
} else {
396
405
throw new ExitError ( `Didn't understand include ${ JSON . stringify ( value ) } ` ) ;
@@ -400,4 +409,13 @@ export class Parser {
400
409
includeDatas . push ( gitlabData ) ;
401
410
return includeDatas ;
402
411
}
412
+
413
+ static parseTemplateInclude ( template : string ) : { project : string , ref : string , file : string , domain : string } {
414
+ return {
415
+ domain : "gitlab.com" ,
416
+ project : "gitlab-org/gitlab" ,
417
+ ref : "master" ,
418
+ file : `lib/gitlab/ci/templates/${ template } `
419
+ }
420
+ }
403
421
}
0 commit comments