diff options
author | André Oliveira <37463445+SpecialAro@users.noreply.github.com> | 2022-07-19 12:52:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-19 12:52:31 +0100 |
commit | 3bb1ca7825a0381ddd8dbe7f44f7dcf4a788b165 (patch) | |
tree | 6b414b9ef3be7656da1717b0d6def62e95d1fb90 /src/helpers/update-helpers.ts | |
parent | fix: remove autoHibernate (diff) | |
download | ferdium-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/update-helpers.ts')
-rw-r--r-- | src/helpers/update-helpers.ts | 65 |
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 @@ | |||
1 | import { Octokit } from '@octokit/core'; | ||
2 | import { defineMessages, IntlShape } from 'react-intl'; | ||
3 | |||
4 | export 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 | |||
15 | export function updateVersionParse(updateVersion: string): string { | ||
16 | return updateVersion !== '' ? `?version=${updateVersion}` : ''; | ||
17 | } | ||
18 | |||
19 | export function onAuthGoToReleaseNotes( | ||
20 | currentLocation: string, | ||
21 | updateVersionParsed: string = '', | ||
22 | ): string { | ||
23 | return currentLocation.includes('#/auth') | ||
24 | ? `#/auth/releasenotes${updateVersionParsed}` | ||
25 | : `#/releasenotes${updateVersionParsed}`; | ||
26 | } | ||
27 | |||
28 | const 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 | |||
41 | export 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 | } | ||