From f5c7feda548a80bd91e29bd09498143d60a0d7ed Mon Sep 17 00:00:00 2001 From: Lee Chun Wei <47494777+chunweii@users.noreply.github.com> Date: Thu, 12 Oct 2023 10:44:42 +0800 Subject: [PATCH] Fetch settings json directly without api (#1215) --- src/app/core/services/github.service.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/core/services/github.service.ts b/src/app/core/services/github.service.ts index 1b9042842..adfc74aa3 100644 --- a/src/app/core/services/github.service.ts +++ b/src/app/core/services/github.service.ts @@ -36,6 +36,9 @@ const { Octokit } = require('@octokit/rest'); const CATCHER_ORG = 'CATcher-org'; const CATCHER_REPO = 'CATcher'; const UNABLE_TO_OPEN_IN_BROWSER = 'Unable to open this issue in Browser'; +function getSettingsUrl(org: string, repoName: string): string { + return `https://raw.githubusercontent.com/${org}/${repoName}/master/settings.json`; +} let ORG_NAME = ''; let MOD_ORG = ''; @@ -398,10 +401,8 @@ export class GithubService { * @return Observable representing session information. */ fetchSettingsFile(): Observable { - return from( - octokit.repos.getContents({ owner: MOD_ORG, repo: DATA_REPO, path: 'settings.json', headers: GithubService.IF_NONE_MATCH_EMPTY }) - ).pipe( - map((rawData) => JSON.parse(atob(rawData['data']['content']))), + return from(fetch(getSettingsUrl(MOD_ORG, DATA_REPO))).pipe( + mergeMap((res) => res.json()), catchError((err) => throwError('Failed to fetch settings file.')) ); }