@@ -17,6 +17,7 @@ import { MetricsReporter, getConnectMetricsInterceptor } from './metrics';
17
17
import { ILogService } from './services/logService' ;
18
18
import { WrapError } from './common/utils' ;
19
19
import { ITelemetryService } from './common/telemetry' ;
20
+ import { ContextURL } from '@gitpod/gitpod-protocol' ;
20
21
21
22
function isTelemetryEnabled ( ) : boolean {
22
23
const TELEMETRY_CONFIG_ID = 'telemetry' ;
@@ -300,14 +301,31 @@ export interface WorkspaceData {
300
301
phase : WorkspacePhase ;
301
302
description : string ;
302
303
lastUsed : Date ;
303
- recentFolders : string [ ] ;
304
+ recentFolders : string [ ] ;
304
305
}
305
306
306
- export function rawWorkspaceToWorkspaceData ( rawWorkspaces : Workspace ) : WorkspaceData ;
307
+ export function rawWorkspaceToWorkspaceData ( rawWorkspaces : Workspace ) : WorkspaceData | undefined ;
307
308
export function rawWorkspaceToWorkspaceData ( rawWorkspaces : Workspace [ ] ) : WorkspaceData [ ] ;
308
309
export function rawWorkspaceToWorkspaceData ( rawWorkspaces : Workspace | Workspace [ ] ) {
309
310
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
+ }
311
329
const provider = url . host . replace ( / \. .+ ?$ / , '' ) ; // remove '.com', etc
312
330
const matches = url . pathname . match ( / [ ^ / ] + / g) ! ; // match /owner/repo
313
331
const owner = matches [ 0 ] ;
@@ -317,7 +335,7 @@ export function rawWorkspaceToWorkspaceData(rawWorkspaces: Workspace | Workspace
317
335
owner,
318
336
repo,
319
337
id : ws . workspaceId ,
320
- contextUrl : ws . context ! . contextUrl ,
338
+ contextUrl : url . toString ( ) ,
321
339
workspaceUrl : ws . status ! . instance ! . status ! . url ,
322
340
phase : WorkspaceInstanceStatus_Phase [ ws . status ! . instance ! . status ! . phase ?? WorkspaceInstanceStatus_Phase . UNSPECIFIED ] . toLowerCase ( ) as WorkspacePhase ,
323
341
description : ws . description ,
@@ -328,7 +346,7 @@ export function rawWorkspaceToWorkspaceData(rawWorkspaces: Workspace | Workspace
328
346
329
347
if ( Array . isArray ( rawWorkspaces ) ) {
330
348
rawWorkspaces = rawWorkspaces . filter ( ws => ws . context ?. details . case === 'git' ) ;
331
- return rawWorkspaces . map ( toWorkspaceData ) ;
349
+ return rawWorkspaces . map ( toWorkspaceData ) . filter ( e => ! ! e ) ;
332
350
}
333
351
334
352
return toWorkspaceData ( rawWorkspaces ) ;
0 commit comments