@@ -23,6 +23,8 @@ import { getPipelineList } from './util/list-tekton-resource';
23
23
import { telemetryLog , telemetryLogError } from './telemetry' ;
24
24
import { checkClusterStatus } from './util/check-cluster-status' ;
25
25
import { treeRefresh } from './util/watchResources' ;
26
+ import { SpawnOptions } from 'child_process' ;
27
+ import { ERR_CLUSTER_TIMED_OUT } from './constants' ;
26
28
27
29
28
30
const tektonResourceCount = { } ;
@@ -72,6 +74,7 @@ export interface Tkn {
72
74
getRawTasks ( ) : Promise < TknTask [ ] > ;
73
75
getClusterTasks ( clustertask ?: TektonNode ) : Promise < TektonNode [ ] > ;
74
76
getRawClusterTasks ( ) : Promise < TknTask [ ] > ;
77
+ executeWithOptions ( command : CliCommand , opts ?: SpawnOptions , fail ?: boolean ) : Promise < CliExitData > ;
75
78
execute ( command : CliCommand , cwd ?: string , fail ?: boolean ) : Promise < CliExitData > ;
76
79
// eslint-disable-next-line @typescript-eslint/ban-types
77
80
executeWatch ( command : CliCommand , opts ?: { } ) : WatchProcess ;
@@ -408,7 +411,7 @@ export class TknImpl implements Tkn {
408
411
private async _getTriggerResource ( trigerResource : TektonNode , command : CliCommand , triggerContextType : ContextType , triggerType : string ) : Promise < TektonNode [ ] > {
409
412
let data : TknPipelineResource [ ] = [ ] ;
410
413
const result = await this . execute ( command , process . cwd ( ) , false ) ;
411
- const triggerCheck = RegExp ( 'undefinederror : the server doesn\'t have a resource type' ) ;
414
+ const triggerCheck = RegExp ( 'error : the server doesn\'t have a resource type' ) ;
412
415
if ( triggerCheck . test ( getStderrString ( result . error ) ) ) {
413
416
telemetryLogError ( `tekton.list.${ triggerType } ` , result . error ) ;
414
417
return ;
@@ -465,7 +468,7 @@ export class TknImpl implements Tkn {
465
468
466
469
async getRawTasks ( ) : Promise < TknTask [ ] > {
467
470
let data : TknTask [ ] = [ ] ;
468
- if ( ! ToolsConfig . getTknLocation ( 'kubectl' ) ) return null ;
471
+ if ( ! ToolsConfig . getToolLocation ( 'kubectl' ) ) return null ;
469
472
const result = await this . execute ( Command . listTasks ( ) ) ;
470
473
if ( result . error ) {
471
474
console . error ( result + 'Std.err when processing tasks' ) ;
@@ -525,7 +528,7 @@ export class TknImpl implements Tkn {
525
528
526
529
async getRawClusterTasks ( ) : Promise < TknTask [ ] > {
527
530
let data : TknTask [ ] = [ ] ;
528
- if ( ! ToolsConfig . getTknLocation ( 'kubectl' ) ) return null ;
531
+ if ( ! ToolsConfig . getToolLocation ( 'kubectl' ) ) return null ;
529
532
const result = await this . execute ( Command . listClusterTasks ( ) ) ;
530
533
if ( result . error ) {
531
534
console . log ( result + 'Std.err when processing tasks' ) ;
@@ -561,10 +564,11 @@ export class TknImpl implements Tkn {
561
564
}
562
565
563
566
async executeInTerminal ( command : CliCommand , resourceName ?: string , cwd : string = process . cwd ( ) , name = 'Tekton' ) : Promise < void > {
564
- let toolLocation = await ToolsConfig . detectOrDownload ( command . cliCommand ) ;
565
- if ( toolLocation ) {
566
- toolLocation = path . dirname ( toolLocation ) ;
567
+ const toolConfig = await ToolsConfig . detectOrDownload ( command . cliCommand ) ;
568
+ if ( ! toolConfig || toolConfig . error == ERR_CLUSTER_TIMED_OUT ) {
569
+ return ;
567
570
}
571
+ const toolLocation = path . dirname ( toolConfig . location ) ;
568
572
let terminal : Terminal ;
569
573
if ( resourceName ) {
570
574
terminal = WindowUtil . createTerminal ( `${ name } :${ resourceName } ` , cwd , toolLocation ) ;
@@ -575,28 +579,46 @@ export class TknImpl implements Tkn {
575
579
terminal . show ( ) ;
576
580
}
577
581
582
+ async executeWithOptions ( command : CliCommand , opts ?: SpawnOptions , fail ?: boolean ) : Promise < CliExitData > {
583
+ const cleanedCommand = await this . createCliCommand ( command ) ;
584
+ if ( typeof cleanedCommand === 'string' ) {
585
+ return {
586
+ error : cleanedCommand ,
587
+ stdout : undefined
588
+ } ;
589
+ }
590
+
591
+ return cli . execute ( command , opts ? opts : { } )
592
+ . then ( async ( result ) => result . error && fail ? Promise . reject ( result . error ) : result )
593
+ . catch ( ( err ) => fail ? Promise . reject ( err ) : Promise . resolve ( { error : null , stdout : '' , stderr : '' } ) ) ;
594
+ }
595
+
578
596
async execute ( command : CliCommand , cwd ?: string , fail = true ) : Promise < CliExitData > {
597
+ return this . executeWithOptions ( command , cwd ? { cwd } : { } , fail ) ;
598
+ }
599
+
600
+ async createCliCommand ( command : CliCommand ) : Promise < CliCommand | string > {
579
601
if ( command . cliCommand . indexOf ( 'tkn' ) >= 0 ) {
580
- const toolLocation = ToolsConfig . getTknLocation ( 'tkn' ) ;
602
+ const toolLocation = ToolsConfig . getToolLocation ( 'tkn' ) ;
581
603
if ( toolLocation ) {
582
- // eslint-disable-next-line require-atomic-updates
583
604
command . cliCommand = command . cliCommand . replace ( 'tkn' , `"${ toolLocation } "` ) . replace ( new RegExp ( '&& tkn' , 'g' ) , `&& "${ toolLocation } "` ) ;
584
605
}
585
606
} else {
586
- const toolLocation = await ToolsConfig . detectOrDownload ( command . cliCommand ) ;
587
- if ( toolLocation ) {
588
- // eslint-disable-next-line require-atomic-updates
589
- command . cliCommand = command . cliCommand . replace ( command . cliCommand , `"${ toolLocation } "` ) . replace ( new RegExp ( `&& ${ command . cliCommand } ` , 'g' ) , `&& "${ toolLocation } "` ) ;
607
+ const toolConfig = await ToolsConfig . detectOrDownload ( command . cliCommand ) ;
608
+ if ( toolConfig ) {
609
+ if ( toolConfig . error === ERR_CLUSTER_TIMED_OUT ) {
610
+ return toolConfig . error ;
611
+ }
612
+ if ( toolConfig . location ) {
613
+ command . cliCommand = command . cliCommand . replace ( command . cliCommand , `"${ toolConfig . location } "` ) . replace ( new RegExp ( `&& ${ command . cliCommand } ` , 'g' ) , `&& "${ toolConfig . location } "` ) ;
614
+ }
590
615
}
591
616
}
592
-
593
- return cli . execute ( command , cwd ? { cwd } : { } )
594
- . then ( async ( result ) => result . error && fail ? Promise . reject ( result . error ) : result )
595
- . catch ( ( err ) => fail ? Promise . reject ( err ) : Promise . resolve ( { error : null , stdout : '' , stderr : '' } ) ) ;
617
+ return command ;
596
618
}
597
619
598
620
executeWatch ( command : CliCommand , cwd ?: string ) : WatchProcess {
599
- const toolLocation = ToolsConfig . getTknLocation ( command . cliCommand ) ;
621
+ const toolLocation = ToolsConfig . getToolLocation ( command . cliCommand ) ;
600
622
if ( toolLocation ) {
601
623
// eslint-disable-next-line require-atomic-updates
602
624
command . cliCommand = command . cliCommand . replace ( command . cliCommand , `"${ toolLocation } "` ) . replace ( new RegExp ( `&& ${ command . cliCommand } ` , 'g' ) , `&& "${ toolLocation } "` ) ;
0 commit comments