File tree 4 files changed +53
-16
lines changed
4 files changed +53
-16
lines changed Original file line number Diff line number Diff line change @@ -12,28 +12,14 @@ import Tooltip from "../components/Tooltip";
12
12
import { getGitpodService } from "../service/service" ;
13
13
import { UserContext } from "../user-context" ;
14
14
import CheckBox from "../components/CheckBox" ;
15
- import { User } from "@gitpod/gitpod-protocol" ;
15
+ import { User , makeIdeVersionHumanReadable } from "@gitpod/gitpod-protocol" ;
16
16
17
17
export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences" ;
18
18
interface SelectIDEProps {
19
19
updateUserContext ?: boolean ;
20
20
location : IDEChangedTrackLocation ;
21
21
}
22
22
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
-
37
23
export const updateUserIDEInfo = async (
38
24
user : User ,
39
25
selectedIde : string ,
@@ -109,7 +95,7 @@ export default function SelectIDE(props: SelectIDEProps) {
109
95
return renderIdeOption (
110
96
option ,
111
97
selected ,
112
- makeVersionHumanReadable ( version ) ,
98
+ makeIdeVersionHumanReadable ( version ) ,
113
99
onSelect ,
114
100
) ;
115
101
} ) }
Original file line number Diff line number Diff line change
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 :-/
Original file line number Diff line number Diff line change @@ -137,3 +137,27 @@ export interface IDEOption {
137
137
*/
138
138
latestImageVersion ?: string ;
139
139
}
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
+ } ;
Original file line number Diff line number Diff line change @@ -20,3 +20,4 @@ export * from "./snapshot-url";
20
20
export * from "./oss-allowlist" ;
21
21
export * from "./installation-admin-protocol" ;
22
22
export * from "./webhook-event" ;
23
+ export * from "./ide-protocol" ;
You can’t perform that action at this time.
0 commit comments