@@ -15,8 +15,8 @@ import Spinner from "../elements/Spinner";
15
15
import Heading from "../typography/Heading" ;
16
16
17
17
interface IProps {
18
- newVersion : string ;
19
- version : string ;
18
+ newVersion : DevelopVersionString ;
19
+ version : DevelopVersionString ;
20
20
onFinished : ( success : boolean ) => void ;
21
21
}
22
22
@@ -32,6 +32,28 @@ interface Commit {
32
32
33
33
const REPOS = [ "element-hq/element-web" , "matrix-org/matrix-js-sdk" ] as const ;
34
34
35
+ export type DevelopVersionString = string & { _developVersionString : never } ;
36
+
37
+ /*
38
+ * Parse a version string is compatible with the Changelog dialog ([element-version]-js-[js-sdk-version])
39
+ */
40
+ export function parseVersion ( version : string ) : Record < ( typeof REPOS ) [ number ] , string > | null {
41
+ const parts = version . split ( "-" ) ;
42
+ if ( parts . length === 3 && parts [ 1 ] === "js" ) {
43
+ const obj : Record < string , string > = { } ;
44
+ for ( let i = 0 ; i < REPOS . length ; i ++ ) {
45
+ const commit = parts [ 2 * i ] ;
46
+ obj [ REPOS [ i ] ] = commit ;
47
+ }
48
+ return obj ;
49
+ }
50
+ return null ;
51
+ }
52
+
53
+ export function checkVersion ( version : string ) : version is DevelopVersionString {
54
+ return parseVersion ( version ) !== null ;
55
+ }
56
+
35
57
export default class ChangelogDialog extends React . Component < IProps , State > {
36
58
public constructor ( props : IProps ) {
37
59
super ( props ) ;
@@ -58,14 +80,11 @@ export default class ChangelogDialog extends React.Component<IProps, State> {
58
80
}
59
81
60
82
public componentDidMount ( ) : void {
61
- const version = this . props . newVersion . split ( "-" ) ;
62
- const version2 = this . props . version . split ( "-" ) ;
63
- if ( version == null || version2 == null ) return ;
64
- // parse versions of form: [vectorversion]-react-[react-sdk-version]-js-[js-sdk-version]
65
- for ( let i = 0 ; i < REPOS . length ; i ++ ) {
66
- const oldVersion = version2 [ 2 * i ] ;
67
- const newVersion = version [ 2 * i ] ;
68
- this . fetchChanges ( REPOS [ i ] , oldVersion , newVersion ) ;
83
+ const commits = parseVersion ( this . props . version ) ! ;
84
+ const newCommits = parseVersion ( this . props . newVersion ) ! ;
85
+
86
+ for ( const repo of REPOS ) {
87
+ this . fetchChanges ( repo , commits [ repo ] , newCommits [ repo ] ) ;
69
88
}
70
89
}
71
90
0 commit comments