From 8afb584024d492c5075267d9963547a0e2ab052c Mon Sep 17 00:00:00 2001 From: Ivan Zosimov Date: Tue, 19 Sep 2023 14:31:18 +0200 Subject: [PATCH] fix: fix review points --- src/distributions/dragonwell/installer.ts | 9 ++------- src/distributions/microsoft/installer.ts | 14 ++++++-------- src/util.ts | 11 +++++++++++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/distributions/dragonwell/installer.ts b/src/distributions/dragonwell/installer.ts index 184bc28..8fb188e 100644 --- a/src/distributions/dragonwell/installer.ts +++ b/src/distributions/dragonwell/installer.ts @@ -4,12 +4,12 @@ import semver from 'semver'; import fs from 'fs'; import path from 'path'; -import {OutgoingHttpHeaders} from 'http'; import {JavaBase} from '../base-installer'; import { extractJdkFile, getDownloadArchiveExtension, + getGitHubHttpHeaders, isVersionSatisfies } from '../../util'; import {IDragonwellVersions, IDragonwellAllVersions} from './models'; @@ -219,8 +219,6 @@ export class DragonwellDistribution extends JavaBase { } private async fetchJsonFromBackupUrl(): Promise { - const token = core.getInput('token'); - const auth = !token ? undefined : `token ${token}`; const owner = 'dragonwell-releng'; const repository = 'dragonwell-setup-java'; const branch = 'main'; @@ -228,10 +226,7 @@ export class DragonwellDistribution extends JavaBase { const backupUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; - const headers: OutgoingHttpHeaders = { - authorization: auth, - accept: 'application/vnd.github.VERSION.raw' - }; + const headers = getGitHubHttpHeaders(); try { core.debug( diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 8b6a7a3..c56fa93 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -4,10 +4,13 @@ import { JavaInstallerOptions, JavaInstallerResults } from '../base-models'; -import {extractJdkFile, getDownloadArchiveExtension} from '../../util'; +import { + extractJdkFile, + getDownloadArchiveExtension, + getGitHubHttpHeaders +} from '../../util'; import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; -import {OutgoingHttpHeaders} from 'http'; import fs from 'fs'; import path from 'path'; import {ITypedResponse} from '@actions/http-client/interfaces'; @@ -85,8 +88,6 @@ export class MicrosoftDistributions extends JavaBase { private async getAvailableVersions(): Promise { // TODO get these dynamically! // We will need Microsoft to add an endpoint where we can query for versions. - const token = core.getInput('token'); - const auth = !token ? undefined : `token ${token}`; const owner = 'actions'; const repository = 'setup-java'; const branch = 'main'; @@ -96,10 +97,7 @@ export class MicrosoftDistributions extends JavaBase { let releases: tc.IToolRelease[] | null = null; const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`; - const headers: OutgoingHttpHeaders = { - authorization: auth, - accept: 'application/vnd.github.VERSION.raw' - }; + const headers = getGitHubHttpHeaders(); let response: ITypedResponse | null = null; diff --git a/src/util.ts b/src/util.ts index fe1078d..8fac693 100644 --- a/src/util.ts +++ b/src/util.ts @@ -7,6 +7,7 @@ import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; import {INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION} from './constants'; +import {OutgoingHttpHeaders} from 'http'; export function getTempDir() { const tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir(); @@ -161,3 +162,13 @@ export function convertVersionToSemver(version: number[] | string) { } return mainVersion; } + +export function getGitHubHttpHeaders(): OutgoingHttpHeaders { + const token = core.getInput('token'); + const auth = !token ? undefined : `token ${token}`; + const headers: OutgoingHttpHeaders = { + authorization: auth, + accept: 'application/vnd.github.VERSION.raw' + }; + return headers; +}