Skip to content

Commit

Permalink
💄
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Jul 17, 2023
1 parent 0c46aea commit 65faaa3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/publicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { MetricsReporter, getConnectMetricsInterceptor } from './metrics';
import { ILogService } from './services/logService';
import { WrapError } from './common/utils';
import { ITelemetryService } from './common/telemetry';
import { ContextURL } from '@gitpod/gitpod-protocol';

function isTelemetryEnabled(): boolean {
const TELEMETRY_CONFIG_ID = 'telemetry';
Expand Down Expand Up @@ -307,10 +308,12 @@ export function rawWorkspaceToWorkspaceData(rawWorkspaces: Workspace): Workspace
export function rawWorkspaceToWorkspaceData(rawWorkspaces: Workspace[]): WorkspaceData[];
export function rawWorkspaceToWorkspaceData(rawWorkspaces: Workspace | Workspace[]) {
const toWorkspaceData = (ws: Workspace) => {
// https://github.com/gitpod-io/gitpod/blob/7e0c605a3d470b8cee0e841e51da9b20022f4f4b/components/public-api-server/pkg/apiv1/workspace.go#L332-L335
// it's always git context, safe to go
const contextUrl = ws.context?.details.case === 'git' ? ws.context.details.value.normalizedContextUrl : ws.context!.contextUrl;
const url = new URL(contextUrl);
let url: URL;
if (ws.context?.details.case === 'git') {
url = new URL(ws.context.details.value.normalizedContextUrl);
} else {
url = ContextURL.getNormalizedURL({ contextURL: ws.context!.contextUrl } as any)!;
}
const provider = url.host.replace(/\..+?$/, ''); // remove '.com', etc
const matches = url.pathname.match(/[^/]+/g)!; // match /owner/repo
const owner = matches[0];
Expand All @@ -320,7 +323,7 @@ export function rawWorkspaceToWorkspaceData(rawWorkspaces: Workspace | Workspace
owner,
repo,
id: ws.workspaceId,
contextUrl,
contextUrl: url.toString(),
workspaceUrl: ws.status!.instance!.status!.url,
phase: WorkspaceInstanceStatus_Phase[ws.status!.instance!.status!.phase ?? WorkspaceInstanceStatus_Phase.UNSPECIFIED].toLowerCase() as WorkspacePhase,
description: ws.description,
Expand Down

0 comments on commit 65faaa3

Please sign in to comment.