Refactor: Simplify getMatchingAsset function parameters in CLI and matcher modules
This commit is contained in:
@@ -273,10 +273,7 @@ async function run() {
|
|||||||
|
|
||||||
console.log(`Fetching latest release for ${repository}...`);
|
console.log(`Fetching latest release for ${repository}...`);
|
||||||
const release = await fetchLatestRelease(repository, token);
|
const release = await fetchLatestRelease(repository, token);
|
||||||
const asset = getMatchingAsset(release.assets, platformInfo, {
|
const asset = getMatchingAsset(release.assets, platformInfo, options.fileName, options.fileType);
|
||||||
fileName: options.fileName,
|
|
||||||
fileType: options.fileType
|
|
||||||
});
|
|
||||||
|
|
||||||
const version = release.tag_name.replace(/^v/i, '');
|
const version = release.tag_name.replace(/^v/i, '');
|
||||||
const downloadUrl = asset.browser_download_url;
|
const downloadUrl = asset.browser_download_url;
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
import { PlatformInfo } from './platform';
|
import { PlatformInfo } from './platform';
|
||||||
|
|
||||||
export interface MatchOptions {
|
|
||||||
fileName?: string;
|
|
||||||
fileType?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeCustomExtensionPattern(fileType: string): string {
|
function normalizeCustomExtensionPattern(fileType: string): string {
|
||||||
let pattern = fileType;
|
let pattern = fileType;
|
||||||
|
|
||||||
@@ -89,8 +84,7 @@ function matchSingleAssetByRegex(assets: any[], pattern: string, noMatchError: s
|
|||||||
return matchingAssets[0];
|
return matchingAssets[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMatchingAsset(assets: any[], platform: PlatformInfo, options: MatchOptions): any {
|
export function getMatchingAsset(assets: any[], platform: PlatformInfo, fileName?: string, fileType?: string): any {
|
||||||
const { fileName, fileType } = options;
|
|
||||||
const extPattern = getExtPattern(fileType, platform.system);
|
const extPattern = getExtPattern(fileType, platform.system);
|
||||||
|
|
||||||
if (!fileName || fileName.startsWith('~')) {
|
if (!fileName || fileName.startsWith('~')) {
|
||||||
|
|||||||
@@ -91,10 +91,7 @@ async function run() {
|
|||||||
|
|
||||||
core.info(`Fetching latest release information for ${repository}...`);
|
core.info(`Fetching latest release information for ${repository}...`);
|
||||||
const release = await fetchLatestRelease(repository, token);
|
const release = await fetchLatestRelease(repository, token);
|
||||||
const asset = getMatchingAsset(release.assets, platformInfo, {
|
const asset = getMatchingAsset(release.assets, platformInfo, fileNameInput, fileType);
|
||||||
fileName: fileNameInput,
|
|
||||||
fileType: fileType
|
|
||||||
});
|
|
||||||
|
|
||||||
core.info(`Selected asset: ${asset.name}`);
|
core.info(`Selected asset: ${asset.name}`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user