mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-01 10:09:50 +00:00
b106668a95
- Convert `param: T | undefined = undefined` to optional `param?: T`. - Drop dead `= false` defaults on the required cache-provider options. - Make `GraphqlPaginatedContent.nodes/edges` optional so the `= []` fallbacks (load-bearing for partial GraphQL connections) are valid. - Type the unchecked `default_branch` response field as optional so the `'HEAD'` fallback is retained. - Drop `tag = undefined` from the Forgejo/Gitea/GitLab preset configs. Part of #43845 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { logger } from '../../../logger/index.ts';
|
|
import { getRepoContents } from '../../../modules/platform/gitea/gitea-helper.ts';
|
|
import type { RepoContents } from '../../../modules/platform/gitea/types.ts';
|
|
import { ExternalHostError } from '../../../types/errors/external-host-error.ts';
|
|
import type { Nullish } from '../../../types/index.ts';
|
|
import type { Preset, PresetConfig } from '../types.ts';
|
|
import { PRESET_DEP_NOT_FOUND, fetchPreset, parsePreset } from '../util.ts';
|
|
|
|
export const Endpoint = 'https://gitea.com/';
|
|
|
|
export async function fetchJSONFile(
|
|
repo: string,
|
|
fileName: string,
|
|
endpoint: string,
|
|
tag?: string | null,
|
|
): Promise<Nullish<Preset>> {
|
|
let res: RepoContents;
|
|
try {
|
|
res = await getRepoContents(repo, fileName, tag, {
|
|
baseUrl: endpoint,
|
|
});
|
|
} 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);
|
|
}
|
|
|
|
return parsePreset(res.contentString, fileName);
|
|
}
|
|
|
|
export function getPresetFromEndpoint(
|
|
repo: string,
|
|
filePreset: string,
|
|
presetPath?: string,
|
|
endpoint = Endpoint,
|
|
tag?: string,
|
|
): Promise<Nullish<Preset>> {
|
|
return fetchPreset({
|
|
repo,
|
|
filePreset,
|
|
presetPath,
|
|
endpoint,
|
|
tag,
|
|
fetch: fetchJSONFile,
|
|
});
|
|
}
|
|
|
|
export function getPreset({
|
|
repo,
|
|
presetName = 'default',
|
|
presetPath,
|
|
tag,
|
|
}: PresetConfig): Promise<Nullish<Preset>> {
|
|
return getPresetFromEndpoint(repo, presetName, presetPath, Endpoint, tag);
|
|
}
|