2018-04-11 23:58:04 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2019-07-31 12:19:29 +01:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2016 Aviral Dasgupta
|
2018-04-11 23:58:04 +01:00
|
|
|
|
2024-09-09 14:57:16 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2018-04-11 23:58:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2018-04-13 00:43:44 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2021-07-02 17:08:27 +02:00
|
|
|
import QuestionDialog from "./QuestionDialog";
|
|
|
|
|
import Spinner from "../elements/Spinner";
|
2023-07-19 09:03:56 +01:00
|
|
|
import Heading from "../typography/Heading";
|
2018-04-11 23:58:04 +01:00
|
|
|
|
2021-06-14 21:26:15 +01:00
|
|
|
interface IProps {
|
2024-10-18 12:20:52 +01:00
|
|
|
newVersion: DevelopVersionString;
|
|
|
|
|
version: DevelopVersionString;
|
2021-06-14 21:26:15 +01:00
|
|
|
onFinished: (success: boolean) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-06 17:21:09 +00:00
|
|
|
type State = Partial<Record<(typeof REPOS)[number], null | string | Commit[]>>;
|
2018-04-11 23:58:04 +01:00
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
interface Commit {
|
|
|
|
|
sha: string;
|
|
|
|
|
html_url: string;
|
|
|
|
|
commit: {
|
|
|
|
|
message: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-15 14:57:26 +01:00
|
|
|
const REPOS = ["element-hq/element-web", "matrix-org/matrix-js-sdk"] as const;
|
2023-02-13 11:39:16 +00:00
|
|
|
|
2024-10-18 12:20:52 +01:00
|
|
|
export type DevelopVersionString = string & { _developVersionString: never };
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Parse a version string is compatible with the Changelog dialog ([element-version]-js-[js-sdk-version])
|
|
|
|
|
*/
|
|
|
|
|
export function parseVersion(version: string): Record<(typeof REPOS)[number], string> | null {
|
|
|
|
|
const parts = version.split("-");
|
|
|
|
|
if (parts.length === 3 && parts[1] === "js") {
|
|
|
|
|
const obj: Record<string, string> = {};
|
|
|
|
|
for (let i = 0; i < REPOS.length; i++) {
|
|
|
|
|
const commit = parts[2 * i];
|
|
|
|
|
obj[REPOS[i]] = commit;
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function checkVersion(version: string): version is DevelopVersionString {
|
|
|
|
|
return parseVersion(version) !== null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
export default class ChangelogDialog extends React.Component<IProps, State> {
|
|
|
|
|
public constructor(props: IProps) {
|
2018-04-11 23:58:04 +01:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {};
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-06 17:21:09 +00:00
|
|
|
private async fetchChanges(repo: (typeof REPOS)[number], oldVersion: string, newVersion: string): Promise<void> {
|
2022-10-12 18:59:07 +01:00
|
|
|
const url = `https://riot.im/github/repos/${repo}/compare/${oldVersion}...${newVersion}`;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(url);
|
|
|
|
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
this.setState({ [repo]: res.statusText });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const body = await res.json();
|
|
|
|
|
this.setState({ [repo]: body.commits });
|
|
|
|
|
} catch (err) {
|
2023-09-26 13:04:17 +01:00
|
|
|
this.setState({ [repo]: err instanceof Error ? err.message : _t("error|unknown") });
|
2022-10-12 18:59:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentDidMount(): void {
|
2024-10-18 12:20:52 +01:00
|
|
|
const commits = parseVersion(this.props.version)!;
|
|
|
|
|
const newCommits = parseVersion(this.props.newVersion)!;
|
|
|
|
|
|
|
|
|
|
for (const repo of REPOS) {
|
|
|
|
|
this.fetchChanges(repo, commits[repo], newCommits[repo]);
|
2018-04-11 23:58:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
private elementsForCommit(commit: Commit): JSX.Element {
|
2018-04-11 23:58:04 +01:00
|
|
|
return (
|
|
|
|
|
<li key={commit.sha} className="mx_ChangelogDialog_li">
|
2020-02-23 22:14:29 +00:00
|
|
|
<a href={commit.html_url} target="_blank" rel="noreferrer noopener">
|
2021-07-19 22:43:11 +01:00
|
|
|
{commit.commit.message.split("\n")[0]}
|
2018-04-11 23:58:04 +01:00
|
|
|
</a>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2018-04-11 23:58:04 +01:00
|
|
|
const logs = REPOS.map((repo) => {
|
2018-12-19 17:26:40 +00:00
|
|
|
let content;
|
|
|
|
|
if (this.state[repo] == null) {
|
|
|
|
|
content = <Spinner key={repo} />;
|
|
|
|
|
} else if (typeof this.state[repo] === "string") {
|
2023-10-03 19:17:26 +01:00
|
|
|
content = _t("update|error_unable_load_commit", {
|
2018-12-19 17:26:40 +00:00
|
|
|
msg: this.state[repo],
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2023-02-13 11:39:16 +00:00
|
|
|
content = (this.state[repo] as Commit[]).map(this.elementsForCommit);
|
2018-12-19 17:26:40 +00:00
|
|
|
}
|
2018-04-11 23:58:04 +01:00
|
|
|
return (
|
|
|
|
|
<div key={repo}>
|
2023-07-19 09:03:56 +01:00
|
|
|
<Heading as="h2" size="4">
|
|
|
|
|
{repo}
|
|
|
|
|
</Heading>
|
2021-07-19 22:43:11 +01:00
|
|
|
<ul>{content}</ul>
|
2018-04-11 23:58:04 +01:00
|
|
|
</div>
|
2018-10-26 22:50:35 -05:00
|
|
|
);
|
2018-04-11 23:58:04 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const content = (
|
|
|
|
|
<div className="mx_ChangelogDialog_content">
|
2023-10-03 19:17:26 +01:00
|
|
|
{this.props.version == null || this.props.newVersion == null ? (
|
|
|
|
|
<h2>{_t("update|unavailable")}</h2>
|
|
|
|
|
) : (
|
|
|
|
|
logs
|
|
|
|
|
)}
|
2018-04-11 23:58:04 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<QuestionDialog
|
2023-10-03 19:17:26 +01:00
|
|
|
title={_t("update|changelog")}
|
2018-04-11 23:58:04 +01:00
|
|
|
description={content}
|
2023-08-23 11:57:22 +01:00
|
|
|
button={_t("action|update")}
|
2018-04-11 23:58:04 +01:00
|
|
|
onFinished={this.props.onFinished}
|
2021-04-27 17:23:27 +02:00
|
|
|
/>
|
2018-10-26 22:50:35 -05:00
|
|
|
);
|
2018-04-11 23:58:04 +01:00
|
|
|
}
|
|
|
|
|
}
|