From 62a27417dcc3c6311475e1d332438fc837c272e9 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 19 Sep 2022 17:26:47 +0200 Subject: [PATCH] fix type --- .../distributors/microsoft-installer.test.ts | 2 +- dist/setup/index.js | 13 +++---------- src/distributions/microsoft/installer.ts | 17 +++++------------ 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/__tests__/distributors/microsoft-installer.test.ts b/__tests__/distributors/microsoft-installer.test.ts index 10335da1..c3e560bf 100644 --- a/__tests__/distributors/microsoft-installer.test.ts +++ b/__tests__/distributors/microsoft-installer.test.ts @@ -19,7 +19,7 @@ describe('findPackageForDownload', () => { spyGetManifestFromRepo = jest.spyOn(httpm.HttpClient.prototype, 'getJson'); spyGetManifestFromRepo.mockReturnValue({ - result: JSON.stringify(data), + result: data, statusCode: 200, headers: {} }); diff --git a/dist/setup/index.js b/dist/setup/index.js index 4b2f80af..e58a8308 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -104460,7 +104460,7 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { const repository = 'setup-java'; const branch = 'add-json-for-microsoft-versions'; const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json'; - let releases = []; + let releases = null; const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; const headers = { authorization: token, @@ -104477,15 +104477,8 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { core.debug(`Http request for microsoft-openjdk-versions.json failed with status code: ${response === null || response === void 0 ? void 0 : response.statusCode}`); return null; } - let versionsRaw = response.result; - if (versionsRaw) { - versionsRaw = versionsRaw.replace(/^\uFEFF/, ''); - try { - releases = JSON.parse(versionsRaw); - } - catch (_a) { - core.debug('Invalid json'); - } + if (response.result) { + releases = response.result; } return releases; }); diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index eda3a050..2d5518ad 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -77,7 +77,7 @@ export class MicrosoftDistributions extends JavaBase { const branch = 'add-json-for-microsoft-versions'; const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json'; - let releases: tc.IToolRelease[] = []; + let releases: tc.IToolRelease[] | null = null; const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; const headers: OutgoingHttpHeaders = { @@ -85,10 +85,10 @@ export class MicrosoftDistributions extends JavaBase { accept: 'application/vnd.github.VERSION.raw' }; - let response: ITypedResponse | null = null; + let response: ITypedResponse | null = null; try { - response = await this.http.getJson(fileUrl, headers); + response = await this.http.getJson(fileUrl, headers); if (!response.result) { return null; } @@ -99,15 +99,8 @@ export class MicrosoftDistributions extends JavaBase { return null; } - let versionsRaw = response.result; - - if (versionsRaw) { - versionsRaw = versionsRaw.replace(/^\uFEFF/, ''); - try { - releases = JSON.parse(versionsRaw); - } catch { - core.debug('Invalid json'); - } + if (response.result) { + releases = response.result; } return releases;