0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/modules/platform/scm.ts
Markus Schulz b2422d86fd
feat: Support for Platform "Gerrit" (#18961)
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2023-12-29 17:55:25 +00:00

39 lines
1.3 KiB
TypeScript

import type { Constructor } from 'type-fest';
import type { PlatformId } from '../../constants';
import { PLATFORM_NOT_FOUND } from '../../constants/error-messages';
import { DefaultGitScm } from './default-scm';
import { GerritScm } from './gerrit/scm';
import { GithubScm } from './github/scm';
import { LocalFs } from './local/scm';
import type { PlatformScm } from './types';
export const platformScmImpls = new Map<PlatformId, Constructor<PlatformScm>>();
platformScmImpls.set('azure', DefaultGitScm);
platformScmImpls.set('codecommit', DefaultGitScm);
platformScmImpls.set('bitbucket', DefaultGitScm);
platformScmImpls.set('bitbucket-server', DefaultGitScm);
platformScmImpls.set('gerrit', GerritScm);
platformScmImpls.set('gitea', DefaultGitScm);
platformScmImpls.set('github', GithubScm);
platformScmImpls.set('gitlab', DefaultGitScm);
platformScmImpls.set('local', LocalFs);
let _scm: PlatformScm | undefined;
const handler: ProxyHandler<PlatformScm> = {
get(_target: PlatformScm, prop: keyof PlatformScm) {
if (!_scm) {
throw new Error(PLATFORM_NOT_FOUND);
}
return _scm[prop];
},
};
export const scm = new Proxy<PlatformScm>({} as any, handler);
export function setPlatformScmApi(name: PlatformId): void {
if (!platformScmImpls.has(name)) {
throw new Error(PLATFORM_NOT_FOUND);
}
_scm = new (platformScmImpls.get(name)!)();
}