forked from renovatebot/renovate
/
index.ts
54 lines (51 loc) · 1.24 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import type { PlatformId } from '../../../constants';
import { GlobalConfig } from '../../global';
import * as gitea from '../gitea';
import * as github from '../github';
import * as gitlab from '../gitlab';
import type { Preset, PresetConfig } from '../types';
import * as local from './common';
interface Resolver {
getPresetFromEndpoint(
repo: string,
filePreset: string,
presetPath?: string,
endpoint?: string,
tag?: string
): Promise<Preset | undefined>;
}
const resolvers = {
azure: local,
bitbucket: local,
'bitbucket-server': local,
codecommit: null,
gitea,
github,
gitlab,
local: null,
} satisfies Record<PlatformId, Resolver | null>;
export function getPreset({
repo,
presetName = 'default',
presetPath,
tag,
}: PresetConfig): Promise<Preset | undefined> {
const { platform, endpoint } = GlobalConfig.get();
if (!platform) {
throw new Error(`Missing platform config for local preset.`);
}
const resolver = resolvers[platform];
if (!resolver) {
throw new Error(
`The platform you're using ($platform) does not support local presets.`
);
}
return resolver.getPresetFromEndpoint(
repo,
presetName,
presetPath,
// TODO: fix type #7154
endpoint!,
tag
);
}