@@ -26,6 +26,8 @@ import validator from 'validator';
2626import { Command } from './odo/command' ;
2727import { CliExitData } from './cli' ;
2828import { Subject } from 'rxjs' ;
29+ import fetch = require( 'make-fetch-happen' ) ;
30+ import { Progress } from './util/progress' ;
2931
3032type ComponentType = Registry ;
3133
@@ -80,11 +82,10 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
8082 }
8183
8284 addRegistry ( newRegistry : Registry ) : void {
83- if ( ! this . registries ) {
85+ if ( ! this . registries ) {
8486 this . registries = [ ] ;
8587 }
8688 this . registries . push ( newRegistry ) ;
87- this . refresh ( false ) ;
8889 this . reveal ( newRegistry ) ;
8990 }
9091
@@ -144,13 +145,13 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
144145 devFileComponentTypes . forEach ( ( component : DevfileComponentType ) => {
145146 getInstance ( ) . execute ( Command . describeCatalogComponent ( component . name , component . registry . name ) ) . then ( ( componentDesc : CliExitData ) => {
146147 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
147- const [ component ] = JSON . parse ( componentDesc . stdout ) as ComponentTypeDescription [ ] ;
148+ const [ component ] = JSON . parse ( componentDesc . stdout ) as ComponentTypeDescription [ ] ;
148149
149- // eslint-disable-next-line max-nested-callbacks
150- component . devfileData . devfile ?. starterProjects ?. map ( ( starter : StarterProject ) => {
151- starter . typeName = component . name ;
152- } ) ;
153- this . compDescriptions . add ( component ) ;
150+ // eslint-disable-next-line max-nested-callbacks
151+ component . devfileData . devfile ?. starterProjects ?. map ( ( starter : StarterProject ) => {
152+ starter . typeName = component . name ;
153+ } ) ;
154+ this . compDescriptions . add ( component ) ;
154155
155156 if ( devFileComponentTypes . length === this . compDescriptions . size ) {
156157 this . subject . next ( 'refresh' ) ;
@@ -320,10 +321,22 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
320321 await vscode . commands . executeCommand ( 'openshift.componentTypesView.registry.remove' , registryContext , true ) ;
321322 }
322323
323- const newRegistry = await OdoImpl . Instance . addRegistry ( regName , regURL , token ) ;
324- ComponentTypesView . instance . addRegistry ( newRegistry ) ;
325-
326- await ComponentTypesView . instance . getAllComponents ( ) ;
324+ try {
325+ const response = await fetch ( regURL , {
326+ method : 'GET' ,
327+ } ) ;
328+ const componentTypes = JSON . parse ( await response . text ( ) ) as DevfileComponentType [ ] ;
329+ if ( componentTypes . length > 0 ) {
330+ void Progress . execFunctionWithProgress ( 'Devfile registry is updating' , async ( ) => {
331+ const newRegistry = await OdoImpl . Instance . addRegistry ( regName , regURL , token ) ;
332+ ComponentTypesView . instance . addRegistry ( newRegistry ) ;
333+ await ComponentTypesView . instance . getAllComponents ( ) ;
334+ ComponentTypesView . instance . refresh ( false ) ;
335+ } )
336+ }
337+ } catch ( error : unknown ) {
338+ void vscode . window . showErrorMessage ( `Invalid registry URL ${ regURL } ` ) ;
339+ }
327340 }
328341
329342 @vsCommand ( 'openshift.componentTypesView.registry.remove' )
0 commit comments