From cf4e1422a00f261bdaf87904e8ae63ed1d2ad2dd Mon Sep 17 00:00:00 2001 From: Ivan Zosimov Date: Mon, 18 Sep 2023 15:53:34 +0200 Subject: [PATCH] feat: update logic of getting json file --- dist/setup/index.js | 14 ++++++++++++-- src/distributions/dragonwell/installer.ts | 21 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index bf0674d..ca30589 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102683,8 +102683,18 @@ class DragonwellDistribution extends base_installer_1.JavaBase { return __awaiter(this, void 0, void 0, function* () { const platform = this.getPlatformOption(); const arch = this.distributionArchitecture(); - const availableVersionsUrl = 'https://raw.githubusercontent.com/dragonwell-releng/dragonwell-setup-java/main/releases.json'; - const fetchedDragonwellVersions = (yield this.http.getJson(availableVersionsUrl)).result; + const token = core.getInput('token'); + const auth = !token ? undefined : `token ${token}`; + const owner = 'dragonwell-releng'; + const repository = 'dragonwell-setup-java'; + const branch = 'main'; + const filePath = 'releases.json'; + const availableVersionsUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; + const headers = { + authorization: auth, + accept: 'application/vnd.github.VERSION.raw' + }; + const fetchedDragonwellVersions = (yield this.http.getJson(availableVersionsUrl, headers)).result; if (!fetchedDragonwellVersions) { throw new Error(`Couldn't fetch any dragonwell versions from ${availableVersionsUrl}`); } diff --git a/src/distributions/dragonwell/installer.ts b/src/distributions/dragonwell/installer.ts index 5a2f834..34e47bc 100644 --- a/src/distributions/dragonwell/installer.ts +++ b/src/distributions/dragonwell/installer.ts @@ -4,6 +4,7 @@ import semver from 'semver'; import fs from 'fs'; import path from 'path'; +import {OutgoingHttpHeaders} from 'http'; import {JavaBase} from '../base-installer'; import { @@ -61,11 +62,25 @@ export class DragonwellDistribution extends JavaBase { const platform = this.getPlatformOption(); const arch = this.distributionArchitecture(); - const availableVersionsUrl = - 'https://raw.githubusercontent.com/dragonwell-releng/dragonwell-setup-java/main/releases.json'; + const token = core.getInput('token'); + const auth = !token ? undefined : `token ${token}`; + const owner = 'dragonwell-releng'; + const repository = 'dragonwell-setup-java'; + const branch = 'main'; + const filePath = 'releases.json'; + + const availableVersionsUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; + + const headers: OutgoingHttpHeaders = { + authorization: auth, + accept: 'application/vnd.github.VERSION.raw' + }; const fetchedDragonwellVersions = ( - await this.http.getJson(availableVersionsUrl) + await this.http.getJson( + availableVersionsUrl, + headers + ) ).result; if (!fetchedDragonwellVersions) {