@@ -17,6 +17,7 @@ import { MetricsReporter, getConnectMetricsInterceptor } from './metrics';
1717import { ILogService } from './services/logService' ;
1818import { WrapError } from './common/utils' ;
1919import { ITelemetryService } from './common/telemetry' ;
20+ import { ContextURL } from '@gitpod/gitpod-protocol' ;
2021
2122function isTelemetryEnabled ( ) : boolean {
2223 const TELEMETRY_CONFIG_ID = 'telemetry' ;
@@ -300,14 +301,31 @@ export interface WorkspaceData {
300301 phase : WorkspacePhase ;
301302 description : string ;
302303 lastUsed : Date ;
303- recentFolders : string [ ] ;
304+ recentFolders : string [ ] ;
304305}
305306
306- export function rawWorkspaceToWorkspaceData ( rawWorkspaces : Workspace ) : WorkspaceData ;
307+ export function rawWorkspaceToWorkspaceData ( rawWorkspaces : Workspace ) : WorkspaceData | undefined ;
307308export function rawWorkspaceToWorkspaceData ( rawWorkspaces : Workspace [ ] ) : WorkspaceData [ ] ;
308309export function rawWorkspaceToWorkspaceData ( rawWorkspaces : Workspace | Workspace [ ] ) {
309310 const toWorkspaceData = ( ws : Workspace ) => {
310- const url = new URL ( ws . context ! . contextUrl ) ;
311+ let url : URL ;
312+ try {
313+ if (
314+ ws . context ?. details . case === 'git' &&
315+ ws . context . details . value . normalizedContextUrl !== ws . context . contextUrl // backward compatible
316+ ) {
317+ url = new URL ( ws . context . details . value . normalizedContextUrl ) ;
318+ } else {
319+ const normalized = ContextURL . getNormalizedURL ( { context : { } , contextURL : ws . context ! . contextUrl } as any ) ;
320+ if ( ! normalized ) {
321+ return undefined ;
322+ }
323+ url = normalized ;
324+ }
325+ } catch ( e ) {
326+ // TODO: send exception
327+ return undefined ;
328+ }
311329 const provider = url . host . replace ( / \. .+ ?$ / , '' ) ; // remove '.com', etc
312330 const matches = url . pathname . match ( / [ ^ / ] + / g) ! ; // match /owner/repo
313331 const owner = matches [ 0 ] ;
@@ -317,7 +335,7 @@ export function rawWorkspaceToWorkspaceData(rawWorkspaces: Workspace | Workspace
317335 owner,
318336 repo,
319337 id : ws . workspaceId ,
320- contextUrl : ws . context ! . contextUrl ,
338+ contextUrl : url . toString ( ) ,
321339 workspaceUrl : ws . status ! . instance ! . status ! . url ,
322340 phase : WorkspaceInstanceStatus_Phase [ ws . status ! . instance ! . status ! . phase ?? WorkspaceInstanceStatus_Phase . UNSPECIFIED ] . toLowerCase ( ) as WorkspacePhase ,
323341 description : ws . description ,
@@ -328,7 +346,7 @@ export function rawWorkspaceToWorkspaceData(rawWorkspaces: Workspace | Workspace
328346
329347 if ( Array . isArray ( rawWorkspaces ) ) {
330348 rawWorkspaces = rawWorkspaces . filter ( ws => ws . context ?. details . case === 'git' ) ;
331- return rawWorkspaces . map ( toWorkspaceData ) ;
349+ return rawWorkspaces . map ( toWorkspaceData ) . filter ( e => ! ! e ) ;
332350 }
333351
334352 return toWorkspaceData ( rawWorkspaces ) ;
0 commit comments