fix: fix review points

This commit is contained in:
Ivan Zosimov 2023-09-19 14:31:18 +02:00
parent 4f1c6f6018
commit 8afb584024
3 changed files with 19 additions and 15 deletions

View File

@ -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<IDragonwellAllVersions | null> {
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(

View File

@ -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<tc.IToolRelease[] | null> {
// 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<tc.IToolRelease[]> | null = null;

View File

@ -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;
}