Skip to content

[JetBrains] display workspace name on the navbar #20544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions components/dashboard/src/workspaces/RenameWorkspaceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@ import { Button } from "@podkit/buttons/Button";
import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
import { useUpdateWorkspaceMutation } from "../data/workspaces/update-workspace-mutation";
import { LoadingButton } from "@podkit/buttons/LoadingButton";
import { Workspace as WorkspaceProtocol } from "@gitpod/gitpod-protocol";

export const NAME_PREFIX = "named:";
export function toWorkspaceName(name: string): string {
// unsetting the name
if (name.trim().length === 0) {
return "no-name";
}
return `${NAME_PREFIX}${name}`;
return WorkspaceProtocol.toWorkspaceName(name);
}

export function fromWorkspaceName(workspace?: Workspace): string | undefined {
if (workspace?.metadata?.name?.startsWith(NAME_PREFIX)) {
return workspace.metadata.name.slice(NAME_PREFIX.length);
}
return undefined;
return WorkspaceProtocol.fromWorkspaceName(workspace?.metadata?.name);
}

type Props = {
Expand Down
14 changes: 14 additions & 0 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,20 @@ export namespace Workspace {
}
return undefined;
}

const NAME_PREFIX = "named:";
export function fromWorkspaceName(name?: Workspace["description"]): string | undefined {
if (name?.startsWith(NAME_PREFIX)) {
return name.slice(NAME_PREFIX.length);
}
return undefined;
}
export function toWorkspaceName(name?: Workspace["description"]): string {
if (!name || name?.trim().length === 0) {
return "no-name";
}
return `${NAME_PREFIX}${name}`;
}
}

export interface GuessGitTokenScopesParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GitpodGatewayClientCustomizationProvider : GatewayClientCustomizationProvi

override val controlCenter: GatewayControlCenterProvider = object : GatewayControlCenterProvider {
override fun getHostnameDisplayKind() = GatewayHostnameDisplayKind.ShowHostnameOnNavbar
override fun getHostnameShort() = title
override fun getHostnameShort() = System.getenv("GITPOD_WORKSPACE_NAME") ?: title
override fun getHostnameLong() = title
}
}
8 changes: 8 additions & 0 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,14 @@ export class WorkspaceStarter {
sysEnvvars.push(isSetJavaXmx);
sysEnvvars.push(isSetJavaProcessorCount);
sysEnvvars.push(disableJetBrainsLocalPortForwarding);

const workspaceName = Workspace.fromWorkspaceName(workspace.description);
if (workspaceName && workspaceName.length > 0) {
const workspaceNameEnv = new EnvironmentVariable();
workspaceNameEnv.setName("GITPOD_WORKSPACE_NAME");
workspaceNameEnv.setValue(workspaceName);
sysEnvvars.push(workspaceNameEnv);
}
const spec = new StartWorkspaceSpec();
await createGitpodTokenPromise;
spec.setEnvvarsList(envvars);
Expand Down
Loading