diff --git a/components/gitpod-protocol/go/gitpod-service.go b/components/gitpod-protocol/go/gitpod-service.go index a6764f5d1947d5..6763ca5326432e 100644 --- a/components/gitpod-protocol/go/gitpod-service.go +++ b/components/gitpod-protocol/go/gitpod-service.go @@ -2250,6 +2250,7 @@ type GetTokenSearchOptions struct { // SetWorkspaceTimeoutResult is the SetWorkspaceTimeoutResult message type type SetWorkspaceTimeoutResult struct { ResetTimeoutOnWorkspaces []string `json:"resetTimeoutOnWorkspaces,omitempty"` + HumanReadableDuration string `json:"humanReadableDuration,omitempty"` } // UserMessage is the UserMessage message type diff --git a/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/entities/SetWorkspaceTimeoutResult.java b/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/entities/SetWorkspaceTimeoutResult.java index 07419701885d27..4b5d07dad06f5a 100644 --- a/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/entities/SetWorkspaceTimeoutResult.java +++ b/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/entities/SetWorkspaceTimeoutResult.java @@ -6,12 +6,18 @@ public class SetWorkspaceTimeoutResult { private String[] resetTimeoutOnWorkspaces; + private String humanReadableDuration; - public SetWorkspaceTimeoutResult(String[] resetTimeoutOnWorkspaces) { + public SetWorkspaceTimeoutResult(String[] resetTimeoutOnWorkspaces, String humanReadableDuration) { this.resetTimeoutOnWorkspaces = resetTimeoutOnWorkspaces; + this.humanReadableDuration = humanReadableDuration; } public String[] getResetTimeoutOnWorkspaces() { return resetTimeoutOnWorkspaces; } + + public String getHumanReadableDuration() { + return humanReadableDuration; + } } diff --git a/components/gitpod-protocol/src/gitpod-service.ts b/components/gitpod-protocol/src/gitpod-service.ts index e479d0308318e8..31f626816a5038 100644 --- a/components/gitpod-protocol/src/gitpod-service.ts +++ b/components/gitpod-protocol/src/gitpod-service.ts @@ -402,6 +402,7 @@ export const createServerMock = function + manager.client.server.setWorkspaceTimeout(workspaceInfo.workspaceId, duration.toString()).whenComplete { result, e -> var message: String var notificationType: NotificationType @@ -85,7 +85,7 @@ class ExtendWorkspaceTimeoutAction : AnAction() { notificationType = NotificationType.ERROR thisLogger().error("gitpod: failed to extend workspace timeout", e) } else { - message = "Workspace timeout has been extended to ${duration}." + message = "Workspace timeout has been extended to ${result.humanReadableDuration}." notificationType = NotificationType.INFORMATION } diff --git a/components/server/ee/src/workspace/gitpod-server-impl.ts b/components/server/ee/src/workspace/gitpod-server-impl.ts index 417a0c99f092bc..161dcf63e6d837 100644 --- a/components/server/ee/src/workspace/gitpod-server-impl.ts +++ b/components/server/ee/src/workspace/gitpod-server-impl.ts @@ -362,6 +362,38 @@ export class GitpodServerEEImpl extends GitpodServerImpl { return { valid: true }; } + goDurationToHumanReadable(goDuration: string): string { + const [, value, unit] = goDuration.match(/^(\d+)([mh])$/)!; + let duration = parseInt(value); + + switch (unit) { + case "m": + duration *= 60; + break; + case "h": + duration *= 60 * 60; + break; + } + + const hours = Math.floor(duration / 3600); + duration %= 3600; + const minutes = Math.floor(duration / 60); + duration %= 60; + + let result = ""; + if (hours) { + result += `${hours} hour${hours === 1 ? "" : "s"}`; + if (minutes) { + result += " and "; + } + } + if (minutes) { + result += `${minutes} minute${minutes === 1 ? "" : "s"}`; + } + + return result; + } + public async setWorkspaceTimeout( ctx: TraceContext, workspaceId: string, @@ -404,6 +436,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl { return { resetTimeoutOnWorkspaces: [workspace.id], + humanReadableDuration: this.goDurationToHumanReadable(validatedDuration), }; }