Skip to content

Commit cebaf02

Browse files
committed
move migrate to resolve
1 parent 1df9c47 commit cebaf02

File tree

3 files changed

+45
-44
lines changed

3 files changed

+45
-44
lines changed

components/server/src/ide-service.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See License-AGPL.txt in the project root for license information.
55
*/
66

7-
import { TaskConfig, Workspace } from "@gitpod/gitpod-protocol";
7+
import { IDESettings, TaskConfig, User, Workspace } from "@gitpod/gitpod-protocol";
88
import { IDEOptions, IDEClient } from "@gitpod/gitpod-protocol/lib/ide-protocol";
99
import {
1010
IDEServiceClient,
@@ -42,6 +42,32 @@ export class IDEService {
4242
}
4343
}
4444

45+
migrateSettings(user: User): IDESettings | undefined {
46+
if (!user?.additionalData?.ideSettings || user.additionalData.ideSettings.settingVersion === "2.0") {
47+
return undefined;
48+
}
49+
const newIDESettings: IDESettings = {
50+
settingVersion: "2.0",
51+
};
52+
const ideSettings = user.additionalData.ideSettings;
53+
if (ideSettings.useDesktopIde) {
54+
if (ideSettings.defaultDesktopIde === "code-desktop") {
55+
newIDESettings.defaultIde = "code-desktop";
56+
} else if (ideSettings.defaultDesktopIde === "code-desktop-insiders") {
57+
newIDESettings.defaultIde = "code-desktop";
58+
newIDESettings.useLatestVersion = true;
59+
} else {
60+
newIDESettings.defaultIde = ideSettings.defaultDesktopIde;
61+
newIDESettings.useLatestVersion = ideSettings.useLatestVersion;
62+
}
63+
} else {
64+
const useLatest = ideSettings.defaultIde === "code-latest";
65+
newIDESettings.defaultIde = "code";
66+
newIDESettings.useLatestVersion = useLatest;
67+
}
68+
return newIDESettings;
69+
}
70+
4571
async resolveWorkspaceConfig(req: ResolveWorkspaceConfigRequest): Promise<ResolveWorkspaceConfigResponse> {
4672
for (let attempt = 0; attempt < 15; attempt++) {
4773
if (attempt != 0) {

components/server/src/workspace/workspace-starter.spec.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66

77
import { User } from "@gitpod/gitpod-protocol";
88
import * as chai from "chai";
9-
import { migrationIDESettings } from "./workspace-starter";
9+
import { IDEService } from "../ide-service";
1010
const expect = chai.expect;
1111

12-
describe("workspace-starter", function () {
13-
describe("migrationIDESettings", function () {
12+
describe("ide-service", function () {
13+
describe("ideService.migrateSettings", function () {
14+
const ideService = new IDEService();
1415
it("with no ideSettings should be undefined", function () {
1516
const user: User = {
1617
id: "string",
1718
creationDate: "string",
1819
identities: [],
1920
additionalData: {},
2021
};
21-
const result = migrationIDESettings(user);
22+
const result = ideService.migrateSettings(user);
2223
expect(result).to.undefined;
2324
});
2425

@@ -35,7 +36,7 @@ describe("workspace-starter", function () {
3536
},
3637
},
3738
};
38-
const result = migrationIDESettings(user);
39+
const result = ideService.migrateSettings(user);
3940
expect(result).to.undefined;
4041
});
4142

@@ -51,7 +52,7 @@ describe("workspace-starter", function () {
5152
},
5253
},
5354
};
54-
const result = migrationIDESettings(user);
55+
const result = ideService.migrateSettings(user);
5556
expect(result?.defaultIde).to.equal("code");
5657
expect(result?.useLatestVersion ?? false).to.be.true;
5758
});
@@ -69,7 +70,7 @@ describe("workspace-starter", function () {
6970
},
7071
},
7172
};
72-
const result = migrationIDESettings(user);
73+
const result = ideService.migrateSettings(user);
7374
expect(result?.defaultIde).to.equal("code-desktop");
7475
expect(result?.useLatestVersion ?? false).to.be.true;
7576
});
@@ -87,7 +88,7 @@ describe("workspace-starter", function () {
8788
},
8889
},
8990
};
90-
const result = migrationIDESettings(user);
91+
const result = ideService.migrateSettings(user);
9192
expect(result?.defaultIde).to.equal("code-desktop");
9293
expect(result?.useLatestVersion ?? false).to.be.false;
9394
});
@@ -106,7 +107,7 @@ describe("workspace-starter", function () {
106107
},
107108
},
108109
};
109-
const result = migrationIDESettings(user);
110+
const result = ideService.migrateSettings(user);
110111
expect(result?.defaultIde).to.equal("intellij");
111112
expect(result?.useLatestVersion ?? false).to.be.false;
112113
});
@@ -125,7 +126,7 @@ describe("workspace-starter", function () {
125126
},
126127
},
127128
};
128-
const result = migrationIDESettings(user);
129+
const result = ideService.migrateSettings(user);
129130
expect(result?.defaultIde).to.equal("intellij");
130131
expect(result?.useLatestVersion ?? false).to.be.true;
131132
});
@@ -144,7 +145,7 @@ describe("workspace-starter", function () {
144145
},
145146
},
146147
};
147-
const result = migrationIDESettings(user);
148+
const result = ideService.migrateSettings(user);
148149
expect(result?.defaultIde).to.equal("code");
149150
expect(result?.useLatestVersion ?? false).to.be.true;
150151
});

components/server/src/workspace/workspace-starter.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import {
5656
ImageConfigFile,
5757
ProjectEnvVar,
5858
ImageBuildLogInfo,
59-
IDESettings,
6059
WithReferrerContext,
6160
EnvVarWithValue,
6261
BillingTier,
@@ -137,32 +136,6 @@ export interface StartWorkspaceOptions {
137136
const MAX_INSTANCE_START_RETRIES = 2;
138137
const INSTANCE_START_RETRY_INTERVAL_SECONDS = 2;
139138

140-
export const migrationIDESettings = (user: User) => {
141-
if (!user?.additionalData?.ideSettings || user.additionalData.ideSettings.settingVersion === "2.0") {
142-
return;
143-
}
144-
const newIDESettings: IDESettings = {
145-
settingVersion: "2.0",
146-
};
147-
const ideSettings = user.additionalData.ideSettings;
148-
if (ideSettings.useDesktopIde) {
149-
if (ideSettings.defaultDesktopIde === "code-desktop") {
150-
newIDESettings.defaultIde = "code-desktop";
151-
} else if (ideSettings.defaultDesktopIde === "code-desktop-insiders") {
152-
newIDESettings.defaultIde = "code-desktop";
153-
newIDESettings.useLatestVersion = true;
154-
} else {
155-
newIDESettings.defaultIde = ideSettings.defaultDesktopIde;
156-
newIDESettings.useLatestVersion = ideSettings.useLatestVersion;
157-
}
158-
} else {
159-
const useLatest = ideSettings.defaultIde === "code-latest";
160-
newIDESettings.defaultIde = "code";
161-
newIDESettings.useLatestVersion = useLatest;
162-
}
163-
return newIDESettings;
164-
};
165-
166139
export async function getWorkspaceClassForInstance(
167140
ctx: TraceContext,
168141
workspace: Workspace,
@@ -297,6 +270,7 @@ export class WorkspaceStarter {
297270
}
298271

299272
const ideConfig = await this.resolveIDEConfiguration(ctx, workspace, user);
273+
300274
// create and store instance
301275
let instance = await this.workspaceDb
302276
.trace({ span })
@@ -379,6 +353,11 @@ export class WorkspaceStarter {
379353
private async resolveIDEConfiguration(ctx: TraceContext, workspace: Workspace, user: User) {
380354
const span = TraceContext.startSpan("resolveIDEConfiguration", ctx);
381355
try {
356+
const migrated = this.ideService.migrateSettings(user);
357+
if (user.additionalData?.ideSettings && migrated) {
358+
user.additionalData.ideSettings = migrated;
359+
}
360+
382361
const workspaceType =
383362
workspace.type === "prebuild"
384363
? IdeServiceApi.WorkspaceType.PREBUILD
@@ -804,11 +783,6 @@ export class WorkspaceStarter {
804783
): Promise<WorkspaceInstance> {
805784
const span = TraceContext.startSpan("newInstance", ctx);
806785
try {
807-
const migrated = migrationIDESettings(user);
808-
if (user.additionalData?.ideSettings && migrated) {
809-
user.additionalData.ideSettings = migrated;
810-
}
811-
812786
const configuration: WorkspaceInstanceConfiguration = {
813787
ideImage: ideConfig.webImage,
814788
supervisorImage: ideConfig.supervisorImage,

0 commit comments

Comments
 (0)