Skip to content

Commit 84b20e4

Browse files
committed
Add check if starter projects exist for selected devfile component
This PR fixes #1854. Signed-off-by: Denis Golovin dgolovin@redhat.com
1 parent 805b604 commit 84b20e4

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

src/odo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ export interface Odo {
366366
deleteURL(url: OpenShiftObject): Promise<OpenShiftObject>;
367367
createComponentCustomUrl(component: OpenShiftObject, name: string, port: string, secure?: boolean): Promise<OpenShiftObject>;
368368
getOpenShiftObjectByContext(context: string): OpenShiftObject;
369+
loadItems<I>(result: cliInstance.CliExitData, fetch: (data) => I[]): I[];
369370
readonly subject: Subject<OdoEvent>;
370371
}
371372

@@ -1094,7 +1095,7 @@ export class OdoImpl implements Odo {
10941095
}
10951096
}
10961097

1097-
private loadItems<I>(result: cliInstance.CliExitData, fetch: (data) => I[] = (data): I[] => data.items): I[] {
1098+
public loadItems<I>(result: cliInstance.CliExitData, fetch: (data) => I[] = (data): I[] => data.items): I[] {
10981099
let data: I[] = [];
10991100
try {
11001101
const items = fetch(JSON.parse(result.stdout));

src/odo/catalog.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface ComponentDescription {
88
metadata: {
99
name: string;
1010
version: string;
11-
},
11+
};
1212
components: [
1313
{
1414
name: 'runtime';
@@ -39,17 +39,8 @@ export interface ComponentDescription {
3939
size: string;
4040
}
4141
}
42-
],
43-
starterProjects: [
44-
{
45-
name: string;
46-
git: {
47-
remotes: {
48-
origin: string;
49-
}
50-
}
51-
}
52-
],
42+
];
43+
starterProjects: StarterProjectDescription[];
5344
commands: [
5445
{
5546
id: string;
@@ -62,5 +53,14 @@ export interface ComponentDescription {
6253
component: string;
6354
}
6455
}
65-
]
56+
];
57+
}
58+
59+
export interface StarterProjectDescription {
60+
name: string;
61+
git: {
62+
remotes: {
63+
origin: string;
64+
}
65+
}
6666
}

src/odo/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class Command {
162162
}
163163

164164
static describeCatalogComponent(component: string): string {
165-
return `odo catalog describe сomponent ${component} -o json`;
165+
return `odo catalog describe component ${component} -o json`;
166166
}
167167

168168
static describeUrl(url: string): string {

src/openshift/component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ import { vsCommand, VsCommandError } from '../vscommand';
2626
import { SourceType } from '../odo/config';
2727
import { ComponentKind, ComponentTypeAdapter } from '../odo/componentType';
2828
import { Url } from '../odo/url';
29+
import { ComponentDescription, StarterProjectDescription } from '../odo/catalog';
2930

3031
import path = require('path');
3132
import globby = require('globby');
3233
import treeKill = require('tree-kill');
3334
import fs = require('fs-extra');
3435

36+
3537
const waitPort = require('wait-port');
3638

3739
export class SourceTypeChoice {
@@ -606,8 +608,12 @@ export class Component extends OpenShiftItem {
606608
const globbyPath = `${folder.fsPath.replace('\\', '/')}/`;
607609
const paths = globby.sync(`${globbyPath}*`, {dot: true, onlyFiles: false});
608610
if (paths.length === 0) {
609-
const create = await window.showQuickPick(['Yes', 'No'] , {placeHolder: 'Initialize Component using default Starter Project?'});
610-
createStarter = create === 'Yes';
611+
const descr = await this.odo.execute(Command.describeCatalogComponent(componentType.name));
612+
const starterProjects: StarterProjectDescription[] =this.odo.loadItems<StarterProjectDescription>(descr,(data:{Data:ComponentDescription})=>data.Data.starterProjects);
613+
if(starterProjects?.length && starterProjects?.length > 0) {
614+
const create = await window.showQuickPick(['Yes', 'No'] , {placeHolder: 'Initialize Component using default Starter Project?'});
615+
createStarter = create === 'Yes';
616+
}
611617
}
612618
}
613619
}

0 commit comments

Comments
 (0)