aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers
diff options
context:
space:
mode:
authorLibravatar André Oliveira <37463445+SpecialAro@users.noreply.github.com>2022-07-19 12:52:31 +0100
committerLibravatar GitHub <noreply@github.com>2022-07-19 12:52:31 +0100
commit3bb1ca7825a0381ddd8dbe7f44f7dcf4a788b165 (patch)
tree6b414b9ef3be7656da1717b0d6def62e95d1fb90 /src/helpers
parentfix: remove autoHibernate (diff)
downloadferdium-app-3bb1ca7825a0381ddd8dbe7f44f7dcf4a788b165.tar.gz
ferdium-app-3bb1ca7825a0381ddd8dbe7f44f7dcf4a788b165.tar.zst
ferdium-app-3bb1ca7825a0381ddd8dbe7f44f7dcf4a788b165.zip
Feature: Add Release Notes (#491)
Co-authored-by: Vijay A <vraravam@users.noreply.github.com> Co-authored-by: Ricardo Cino <ricardo@cino.io>
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/update-helpers.ts65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/helpers/update-helpers.ts b/src/helpers/update-helpers.ts
new file mode 100644
index 000000000..daeef5413
--- /dev/null
+++ b/src/helpers/update-helpers.ts
@@ -0,0 +1,65 @@
1import { Octokit } from '@octokit/core';
2import { defineMessages, IntlShape } from 'react-intl';
3
4export function getFerdiumVersion(
5 currentLocation: string,
6 ferdiumVersion: string,
7): string {
8 const matches = currentLocation?.match(/version=([^&]*)/);
9 if (matches !== null) {
10 return `v${matches[1]}`;
11 }
12 return `v${ferdiumVersion}`;
13}
14
15export function updateVersionParse(updateVersion: string): string {
16 return updateVersion !== '' ? `?version=${updateVersion}` : '';
17}
18
19export function onAuthGoToReleaseNotes(
20 currentLocation: string,
21 updateVersionParsed: string = '',
22): string {
23 return currentLocation.includes('#/auth')
24 ? `#/auth/releasenotes${updateVersionParsed}`
25 : `#/releasenotes${updateVersionParsed}`;
26}
27
28const messages = defineMessages({
29 connectionError: {
30 id: 'settings.releasenotes.connectionError',
31 defaultMessage:
32 'An error occured when connecting to Github, please try again later.',
33 },
34 connectionErrorPageMissing: {
35 id: 'settings.releasenotes.connectionErrorPageMissing',
36 defaultMessage:
37 'An error occured when connecting to Github, the page you are looking for is missing.',
38 },
39});
40
41export async function getUpdateInfoFromGH(
42 currentLocation: string,
43 ferdiumVersion: string,
44 intl: IntlShape,
45): Promise<string> {
46 const octokit = new Octokit();
47 try {
48 const response = await octokit.request(
49 'GET /repos/{owner}/{repo}/releases/tags/{tag}',
50 {
51 owner: 'ferdium',
52 repo: 'ferdium-app',
53 tag: getFerdiumVersion(currentLocation, ferdiumVersion),
54 },
55 );
56
57 if (response.status === 200) {
58 const json = response.data.body;
59 return json || `### ${intl.formatMessage(messages.connectionError)}`;
60 }
61 return `### ${intl.formatMessage(messages.connectionError)}`;
62 } catch {
63 return `### ${intl.formatMessage(messages.connectionErrorPageMissing)}`;
64 }
65}