Skip to content

Commit 3cca423

Browse files
committed
Move function to ide-protocol
1 parent a9bb3eb commit 3cca423

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

components/dashboard/src/settings/SelectIDE.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,14 @@ import Tooltip from "../components/Tooltip";
1212
import { getGitpodService } from "../service/service";
1313
import { UserContext } from "../user-context";
1414
import CheckBox from "../components/CheckBox";
15-
import { User } from "@gitpod/gitpod-protocol";
15+
import { User, makeIdeVersionHumanReadable } from "@gitpod/gitpod-protocol";
1616

1717
export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences";
1818
interface SelectIDEProps {
1919
updateUserContext?: boolean;
2020
location: IDEChangedTrackLocation;
2121
}
2222

23-
const makeVersionHumanReadable = (versionString?: string) => {
24-
if (!versionString) {
25-
return undefined;
26-
}
27-
28-
let [version, pre] = versionString.split("-");
29-
if (pre) {
30-
// Capitalize the string, so that 1.74.0-insider becomes 1.74.0 Insider
31-
pre = pre[0].toUpperCase() + pre.slice(1);
32-
}
33-
34-
return [version, pre].join(" ").trim();
35-
};
36-
3723
export const updateUserIDEInfo = async (
3824
user: User,
3925
selectedIde: string,
@@ -109,7 +95,7 @@ export default function SelectIDE(props: SelectIDEProps) {
10995
return renderIdeOption(
11096
option,
11197
selected,
112-
makeVersionHumanReadable(version),
98+
makeIdeVersionHumanReadable(version),
11399
onSelect,
114100
);
115101
})}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { suite, test } from "mocha-typescript";
8+
import * as chai from "chai";
9+
import { makeIdeVersionHumanReadable } from ".";
10+
11+
const expect = chai.expect;
12+
13+
@suite
14+
class TestIdeProtocol {
15+
@test public testSuffixedIdeVersion() {
16+
const versionString = "v1.74.0-insider";
17+
18+
expect(makeIdeVersionHumanReadable(versionString)).to.deep.equal("v1.74.0 Insider");
19+
}
20+
@test public testUnsuffixedIdeVersion() {
21+
const versionString = "v1.74.0";
22+
23+
expect(makeIdeVersionHumanReadable(versionString)).to.deep.equal("v1.74.0");
24+
}
25+
}
26+
module.exports = new TestIdeProtocol(); // Only to circumvent no usage warning :-/

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,27 @@ export interface IDEOption {
137137
*/
138138
latestImageVersion?: string;
139139
}
140+
141+
/**
142+
* Takes a version string of the form `X.Y.Z-<pre-release-tag>` and returns a human-readable version string
143+
* where the pre-release tag is capitalized and separated from the version number by a space.
144+
*
145+
* @example
146+
* makeIdeVersionHumanReadable("1.74.0-insider") // returns "1.74.0 Insider"
147+
*
148+
* @param [versionString] - The version string to convert to human-readable format
149+
* @returns A human-readable version string, or `undefined` if `versionString` is falsy
150+
*/
151+
export const makeIdeVersionHumanReadable = (versionString?: string): string | undefined => {
152+
if (!versionString) {
153+
return undefined;
154+
}
155+
156+
let [version, pre] = versionString.split("-");
157+
if (pre) {
158+
// Capitalize the string, so that 1.74.0-insider becomes 1.74.0 Insider
159+
pre = pre[0].toUpperCase() + pre.slice(1);
160+
}
161+
162+
return [version, pre].join(" ").trim();
163+
};

components/gitpod-protocol/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ export * from "./snapshot-url";
2020
export * from "./oss-allowlist";
2121
export * from "./installation-admin-protocol";
2222
export * from "./webhook-event";
23+
export * from "./ide-protocol";

0 commit comments

Comments
 (0)