@@ -9,112 +9,145 @@ import { CommandOption, CommandText } from '../base/command';
99import { CliChannel } from '../cli' ;
1010import { Progress } from '../util/progress' ;
1111import { VsCommandError , vsCommand } from '../vscommand' ;
12+ import { OpenShiftTerminalManager } from '../webview/openshift-terminal/openShiftTerminal' ;
1213import * as common from './common' ;
1314
1415export class Build {
15-
1616 public static command = {
17- getAllBuilds ( parent : ClusterExplorerV1 . ClusterExplorerNode ) : CommandText {
18- return new CommandText ( 'get build' ,
19- undefined , [
20- new CommandOption ( '-o' , `jsonpath="{range .items[?(.metadata.labels.buildconfig=='${ ( parent as any ) . name } ')]}{.metadata.namespace}{','}{.metadata.name}{','}{.metadata.annotations.openshift\\.io/build\\.number}{\\"\\n\\"}{end}"` )
21- ]
22- ) ;
23- } ,
24- startBuild ( buildConfig : string ) : CommandText {
25- return new CommandText ( 'oc start-build' , buildConfig ) ;
26- } ,
27- getBuilds ( build : string ) : CommandText {
28- return new CommandText ( 'oc get build' ,
29- undefined , [
17+ getAllBuilds ( parent : ClusterExplorerV1 . ClusterExplorerNode ) : CommandText {
18+ return new CommandText ( 'get build' , undefined , [
19+ new CommandOption (
20+ '-o' ,
21+ `jsonpath="{range .items[?(.metadata.labels.buildconfig=='${
22+ ( parent as any ) . name
23+ } ')]}{.metadata.namespace}{','}{.metadata.name}{','}{.metadata.annotations.openshift\\.io/build\\.number}{\\"\\n\\"}{end}"`,
24+ ) ,
25+ ] ) ;
26+ } ,
27+ startBuild ( buildConfig : string ) : CommandText {
28+ return new CommandText ( 'oc start-build' , buildConfig ) ;
29+ } ,
30+ getBuilds ( build : string ) : CommandText {
31+ return new CommandText ( 'oc get build' , undefined , [
3032 new CommandOption ( '-l' , `buildconfig=${ build } ` ) ,
31- new CommandOption ( '-o' , 'json' , false )
32- ]
33- ) ;
34- } ,
35- showLog ( build : string , text : string ) : CommandText {
36- return new CommandText ( 'oc logs' , `${ build } ${ text } ` ) ;
37- } ,
38- rebuildFrom ( resourceId : string ) : CommandText {
39- return new CommandText ( 'oc start-build' ,
40- undefined , [
41- new CommandOption ( '--from-build' , resourceId )
42- ]
43- ) ;
44- } ,
45- followLog ( build : string , text : string ) : CommandText {
46- return new CommandText ( 'oc logs' , `${ build } ${ text } ` , [
47- new CommandOption ( '-f' )
48- ]
49- ) ;
50- } ,
51- delete ( build : string ) : CommandText {
52- return new CommandText ( 'oc delete build' , build ) ;
53- } ,
54- getBuildConfigs ( ) : CommandText {
55- return new CommandText ( 'oc get buildConfig -o json' ) ;
56- }
57- } ;
33+ new CommandOption ( '-o' , 'json' , false ) ,
34+ ] ) ;
35+ } ,
36+ showLog ( build : string , text : string ) : CommandText {
37+ return new CommandText ( 'oc logs' , `${ build } ${ text } ` ) ;
38+ } ,
39+ rebuildFrom ( resourceId : string ) : CommandText {
40+ return new CommandText ( 'oc start-build' , undefined , [
41+ new CommandOption ( '--from-build' , resourceId ) ,
42+ ] ) ;
43+ } ,
44+ followLog ( build : string , text : string ) : CommandText {
45+ return new CommandText ( 'oc logs' , `${ build } ${ text } ` , [ new CommandOption ( '-f' ) ] ) ;
46+ } ,
47+ delete ( build : string ) : CommandText {
48+ return new CommandText ( 'oc delete build' , build ) ;
49+ } ,
50+ getBuildConfigs ( ) : CommandText {
51+ return new CommandText ( 'oc get buildConfig -o json' ) ;
52+ } ,
53+ } ;
5854
5955 protected static readonly cli = CliChannel . getInstance ( ) ;
6056
6157 static getNodeContributor ( ) : ClusterExplorerV1 . NodeContributor {
62- return {
63- contributesChildren ( parent : ClusterExplorerV1 . ClusterExplorerNode | undefined ) : boolean {
64- return ! ! parent && parent . nodeType === 'resource' && parent . resourceKind . manifestKind === 'BuildConfig' ;
65- } ,
66- async getChildren ( parent : ClusterExplorerV1 . ClusterExplorerNode | undefined ) : Promise < ClusterExplorerV1 . Node [ ] > {
67- return common . getChildrenNode ( Build . command . getAllBuilds ( parent ) , 'Build' , 'build' ) ;
68- }
69- } ;
58+ return {
59+ contributesChildren (
60+ parent : ClusterExplorerV1 . ClusterExplorerNode | undefined ,
61+ ) : boolean {
62+ return (
63+ ! ! parent &&
64+ parent . nodeType === 'resource' &&
65+ parent . resourceKind . manifestKind === 'BuildConfig'
66+ ) ;
67+ } ,
68+ async getChildren (
69+ parent : ClusterExplorerV1 . ClusterExplorerNode | undefined ,
70+ ) : Promise < ClusterExplorerV1 . Node [ ] > {
71+ return common . getChildrenNode ( Build . command . getAllBuilds ( parent ) , 'Build' , 'build' ) ;
72+ } ,
73+ } ;
7074 }
7175
7276 static async getBuildConfigNames ( msg : string ) : Promise < QuickPickItem [ ] > {
7377 return common . getQuickPicks ( Build . command . getBuildConfigs ( ) , msg ) ;
7478 }
7579
7680 static async getBuildNames ( buildConfig : string ) : Promise < QuickPickItem [ ] > {
77- return common . getQuickPicks ( Build . command . getBuilds ( buildConfig ) , 'You have no builds available' ) ;
81+ return common . getQuickPicks (
82+ Build . command . getBuilds ( buildConfig ) ,
83+ 'You have no builds available' ,
84+ ) ;
7885 }
7986
8087 static async selectBuild ( context : any , text : string ) : Promise < string > {
8188 let build : string = null ;
8289 if ( context ) {
8390 build = context . impl . name ;
8491 } else {
85- const buildConfig = await common . selectResourceByName ( Build . getBuildConfigNames ( 'You have no BuildConfigs available' ) , 'Select a BuildConfig to see the builds' ) ;
86- if ( buildConfig ) {
87- const selBuild = await window . showQuickPick ( this . getBuildNames ( buildConfig ) , { placeHolder : text , ignoreFocusOut : true } ) ;
92+ const buildConfig = await common . selectResourceByName (
93+ Build . getBuildConfigNames ( 'You have no BuildConfigs available' ) ,
94+ 'Select a BuildConfig to see the builds' ,
95+ ) ;
96+ if ( buildConfig ) {
97+ const selBuild = await window . showQuickPick ( this . getBuildNames ( buildConfig ) , {
98+ placeHolder : text ,
99+ ignoreFocusOut : true ,
100+ } ) ;
88101 build = selBuild ? selBuild . label : null ;
89102 }
90103 }
91104 return build ;
92105 }
93106
94107 @vsCommand ( 'clusters.openshift.build.start' )
95- static async startBuild ( context : { name : string } ) : Promise < string > {
108+ static async startBuild ( context : { name : string } ) : Promise < string > {
96109 let buildName : string = context ? context . name : undefined ;
97110 let result : Promise < string > = null ;
98- if ( ! buildName ) buildName = await common . selectResourceByName ( await Build . getBuildConfigNames ( 'You have no BuildConfigs available to start a build' ) , 'Select a BuildConfig to start a build' ) ;
111+ if ( ! buildName ) {
112+ buildName = await common . selectResourceByName (
113+ await Build . getBuildConfigNames (
114+ 'You have no BuildConfigs available to start a build' ,
115+ ) ,
116+ 'Select a BuildConfig to start a build' ,
117+ ) ;
118+ }
99119 if ( buildName ) {
100- result = Progress . execFunctionWithProgress ( 'Starting build' , ( ) => Build . cli . executeTool ( Build . command . startBuild ( buildName ) ) )
120+ result = Progress . execFunctionWithProgress ( 'Starting build' , ( ) =>
121+ Build . cli . executeTool ( Build . command . startBuild ( buildName ) ) ,
122+ )
101123 . then ( ( ) => `Build '${ buildName } ' successfully started` )
102- . catch ( ( err ) => Promise . reject ( new VsCommandError ( `Failed to start build with error '${ err } '` , 'Failed to start build' ) ) ) ;
124+ . catch ( ( err ) =>
125+ Promise . reject (
126+ new VsCommandError (
127+ `Failed to start build with error '${ err } '` ,
128+ 'Failed to start build' ,
129+ ) ,
130+ ) ,
131+ ) ;
103132 }
104133 return result ;
105134 }
106135
107136 @vsCommand ( 'clusters.openshift.build.showLog' , true )
108- static async showLog ( context : { impl : any } ) : Promise < string > {
137+ static async showLog ( context : { impl : any } ) : Promise < string > {
109138 const build = await Build . selectBuild ( context , 'Select a Build to see the logs' ) ;
110139 if ( build ) {
111- void Build . cli . executeInTerminal ( Build . command . showLog ( build , '-build' ) , undefined , `Show '${ build } ' Build Log` ) ;
140+ OpenShiftTerminalManager . getInstance ( ) . executeInTerminal (
141+ Build . command . showLog ( build , '-build' ) ,
142+ undefined ,
143+ `Show '${ build } ' Build Log` ,
144+ ) ;
112145 }
113146 return null ;
114147 }
115148
116149 @vsCommand ( 'clusters.openshift.build.rebuild' )
117- static async rebuild ( context : { id ?: string ; impl : any } ) : Promise < string > {
150+ static async rebuild ( context : { id ?: string ; impl : any } ) : Promise < string > {
118151 let resourceId : string ;
119152 if ( context ) {
120153 resourceId = context . impl . name ;
@@ -125,28 +158,45 @@ export class Build {
125158 }
126159 }
127160 if ( resourceId ) {
128- void Build . cli . executeInTerminal ( Build . command . rebuildFrom ( resourceId ) , undefined , `Rebuild '${ resourceId } ' Build` ) ;
161+ OpenShiftTerminalManager . getInstance ( ) . executeInTerminal (
162+ Build . command . rebuildFrom ( resourceId ) ,
163+ undefined ,
164+ `Rebuild '${ resourceId } ' Build` ,
165+ ) ;
129166 }
130167 return null ;
131168 }
132169
133170 @vsCommand ( 'clusters.openshift.build.followLog' )
134- static async followLog ( context : { impl : any } ) : Promise < string > {
171+ static async followLog ( context : { impl : any } ) : Promise < string > {
135172 const build = await Build . selectBuild ( context , 'Select a build to follow the logs' ) ;
136173 if ( build ) {
137- void Build . cli . executeInTerminal ( Build . command . followLog ( build , '-build' ) , undefined , `Follow '${ build } ' Build Log` ) ;
174+ OpenShiftTerminalManager . getInstance ( ) . executeInTerminal (
175+ Build . command . followLog ( build , '-build' ) ,
176+ undefined ,
177+ `Follow '${ build } ' Build Log` ,
178+ ) ;
138179 }
139180 return null ;
140181 }
141182
142183 @vsCommand ( 'clusters.openshift.build.delete' , true )
143- static async delete ( context : { impl : any } ) : Promise < string > {
184+ static async delete ( context : { impl : any } ) : Promise < string > {
144185 let result : null | string | Promise < string > | PromiseLike < string > = null ;
145186 const build = await Build . selectBuild ( context , 'Select a build to delete' ) ;
146187 if ( build ) {
147- result = Progress . execFunctionWithProgress ( 'Deleting build' , ( ) => Build . cli . executeTool ( Build . command . delete ( build ) ) )
188+ result = Progress . execFunctionWithProgress ( 'Deleting build' , ( ) =>
189+ Build . cli . executeTool ( Build . command . delete ( build ) ) ,
190+ )
148191 . then ( ( ) => `Build '${ build } ' successfully deleted` )
149- . catch ( ( err ) => Promise . reject ( new VsCommandError ( `Failed to delete build with error '${ err } '` , 'Failed to delete build' ) ) ) ;
192+ . catch ( ( err ) =>
193+ Promise . reject (
194+ new VsCommandError (
195+ `Failed to delete build with error '${ err } '` ,
196+ 'Failed to delete build' ,
197+ ) ,
198+ ) ,
199+ ) ;
150200 }
151201 return result ;
152202 }
0 commit comments