Skip to content

Commit 8af4a7e

Browse files
committed
Add humanReadableDuration as return value from setWorkspaceTimeout
1 parent 869ffcf commit 8af4a7e

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

components/gitpod-protocol/go/gitpod-service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,7 @@ type GetTokenSearchOptions struct {
22502250
// SetWorkspaceTimeoutResult is the SetWorkspaceTimeoutResult message type
22512251
type SetWorkspaceTimeoutResult struct {
22522252
ResetTimeoutOnWorkspaces []string `json:"resetTimeoutOnWorkspaces,omitempty"`
2253+
HumanReadableDuration string `json:"humanReadableDuration,omitempty"`
22532254
}
22542255

22552256
// UserMessage is the UserMessage message type

components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/entities/SetWorkspaceTimeoutResult.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66

77
public class SetWorkspaceTimeoutResult {
88
private String[] resetTimeoutOnWorkspaces;
9+
private String humanReadableDuration;
910

10-
public SetWorkspaceTimeoutResult(String[] resetTimeoutOnWorkspaces) {
11+
public SetWorkspaceTimeoutResult(String[] resetTimeoutOnWorkspaces, String humanReadableDuration) {
1112
this.resetTimeoutOnWorkspaces = resetTimeoutOnWorkspaces;
13+
this.humanReadableDuration = humanReadableDuration;
1214
}
1315

1416
public String[] getResetTimeoutOnWorkspaces() {
1517
return resetTimeoutOnWorkspaces;
1618
}
19+
20+
public String getHumanReadableDuration() {
21+
return humanReadableDuration;
22+
}
1723
}

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ export const createServerMock = function <C extends GitpodClient, S extends Gitp
402402

403403
export interface SetWorkspaceTimeoutResult {
404404
resetTimeoutOnWorkspaces: string[];
405+
humanReadableDuration: string;
405406
}
406407

407408
export interface GetWorkspaceTimeoutResult {

components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/actions/ExtendWorkspaceTimeoutAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ExtendWorkspaceTimeoutAction : AnAction() {
7676
val dialog = InputDurationDialog()
7777
if (dialog.showAndGet()) {
7878
val duration = dialog.getDuration()
79-
manager.client.server.setWorkspaceTimeout(workspaceInfo.workspaceId, duration.toString()).whenComplete { _, e ->
79+
manager.client.server.setWorkspaceTimeout(workspaceInfo.workspaceId, duration.toString()).whenComplete { result, e ->
8080
var message: String
8181
var notificationType: NotificationType
8282

@@ -85,7 +85,7 @@ class ExtendWorkspaceTimeoutAction : AnAction() {
8585
notificationType = NotificationType.ERROR
8686
thisLogger().error("gitpod: failed to extend workspace timeout", e)
8787
} else {
88-
message = "Workspace timeout has been extended to ${duration}."
88+
message = "Workspace timeout has been extended to ${result.humanReadableDuration}."
8989
notificationType = NotificationType.INFORMATION
9090
}
9191

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,38 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
362362
return { valid: true };
363363
}
364364

365+
goDurationToHumanReadable(goDuration: string): string {
366+
const [, value, unit] = goDuration.match(/^(\d+)([mh])$/)!;
367+
let duration = parseInt(value);
368+
369+
switch (unit) {
370+
case "m":
371+
duration *= 60;
372+
break;
373+
case "h":
374+
duration *= 60 * 60;
375+
break;
376+
}
377+
378+
const hours = Math.floor(duration / 3600);
379+
duration %= 3600;
380+
const minutes = Math.floor(duration / 60);
381+
duration %= 60;
382+
383+
let result = "";
384+
if (hours) {
385+
result += `${hours} hour${hours === 1 ? "" : "s"}`;
386+
if (minutes) {
387+
result += " and ";
388+
}
389+
}
390+
if (minutes) {
391+
result += `${minutes} minute${minutes === 1 ? "" : "s"}`;
392+
}
393+
394+
return result;
395+
}
396+
365397
public async setWorkspaceTimeout(
366398
ctx: TraceContext,
367399
workspaceId: string,
@@ -404,6 +436,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
404436

405437
return {
406438
resetTimeoutOnWorkspaces: [workspace.id],
439+
humanReadableDuration: this.goDurationToHumanReadable(validatedDuration),
407440
};
408441
}
409442

0 commit comments

Comments
 (0)