0
0
Fork 0
mirror of https://github.com/renovatebot/renovate.git synced 2025-01-27 05:09:37 +00:00
renovatebot_renovate/lib/config/presets/local/common.ts
renovate[bot] 4f1fb3a163
chore(deps): update linters to v8.5.0 (#31349)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2024-09-16 07:10:17 +00:00

50 lines
1.1 KiB
TypeScript

import { logger } from '../../../logger';
import { platform } from '../../../modules/platform';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import type { Preset } from '../types';
import { PRESET_DEP_NOT_FOUND, fetchPreset, parsePreset } from '../util';
export async function fetchJSONFile(
repo: string,
fileName: string,
_endpoint?: string,
tag?: string,
): Promise<Preset> {
let raw: string | null;
try {
raw = await platform.getRawFile(fileName, repo, tag ?? undefined);
} catch (err) {
if (err instanceof ExternalHostError) {
throw err;
}
logger.debug(
`Preset file ${fileName} not found in ${repo}: ${err.message}}`,
);
throw new Error(PRESET_DEP_NOT_FOUND);
}
if (!raw) {
throw new Error(PRESET_DEP_NOT_FOUND);
}
return parsePreset(raw, fileName);
}
export function getPresetFromEndpoint(
repo: string,
filePreset: string,
presetPath: string | undefined,
endpoint: string,
tag?: string,
): Promise<Preset | undefined> {
return fetchPreset({
repo,
filePreset,
presetPath,
endpoint,
tag,
fetch: fetchJSONFile,
});
}