Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(manager): add renovate config presets manager #32688

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
479 changes: 0 additions & 479 deletions lib/config/presets/index.spec.ts

Large diffs are not rendered by default.

124 changes: 2 additions & 122 deletions lib/config/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import * as http from './http';
import * as internal from './internal';
import * as local from './local';
import * as npm from './npm';
import type { ParsedPreset, Preset, PresetApi } from './types';
import { parsePreset } from './parse';
import type { Preset, PresetApi } from './types';
import {
PRESET_DEP_NOT_FOUND,
PRESET_INVALID,
Expand All @@ -46,13 +47,6 @@ const presetSources: Record<string, PresetApi> = {

const presetCacheNamespace = 'preset';

const nonScopedPresetWithSubdirRegex = regEx(
/^(?<repo>~?[\w\-. /]+?)\/\/(?:(?<presetPath>[\w\-./]+)\/)?(?<presetName>[\w\-.]+)(?:#(?<tag>[\w\-./]+?))?$/,
);
const gitPresetRegex = regEx(
/^(?<repo>~?[\w\-. /]+)(?::(?<presetName>[\w\-.+/]+))?(?:#(?<tag>[\w\-./]+?))?$/,
);

export function replaceArgs(
obj: string,
argMapping: Record<string, any>,
Expand Down Expand Up @@ -105,120 +99,6 @@ export function replaceArgs(
return obj;
}

export function parsePreset(input: string): ParsedPreset {
let str = input;
let presetSource: string | undefined;
let presetPath: string | undefined;
let repo: string;
let presetName: string;
let tag: string | undefined;
let params: string[] | undefined;
if (str.startsWith('github>')) {
presetSource = 'github';
str = str.substring('github>'.length);
} else if (str.startsWith('gitlab>')) {
presetSource = 'gitlab';
str = str.substring('gitlab>'.length);
} else if (str.startsWith('gitea>')) {
presetSource = 'gitea';
str = str.substring('gitea>'.length);
} else if (str.startsWith('local>')) {
presetSource = 'local';
str = str.substring('local>'.length);
} else if (str.startsWith('http://') || str.startsWith('https://')) {
presetSource = 'http';
} else if (
!str.startsWith('@') &&
!str.startsWith(':') &&
str.includes('/')
) {
presetSource = 'local';
}
str = str.replace(regEx(/^npm>/), '');
presetSource = presetSource ?? 'npm';
if (str.includes('(')) {
params = str
.slice(str.indexOf('(') + 1, -1)
.split(',')
.map((elem) => elem.trim());
str = str.slice(0, str.indexOf('('));
}
if (presetSource === 'http') {
return { presetSource, repo: str, presetName: '', params };
}
const presetsPackages = [
'compatibility',
'config',
'customManagers',
'default',
'docker',
'group',
'helpers',
'mergeConfidence',
'monorepo',
'npm',
'packages',
'preview',
'replacements',
'schedule',
'security',
'workarounds',
];
if (
presetsPackages.some((presetPackage) => str.startsWith(`${presetPackage}:`))
) {
presetSource = 'internal';
[repo, presetName] = str.split(':');
} else if (str.startsWith(':')) {
// default namespace
presetSource = 'internal';
repo = 'default';
presetName = str.slice(1);
} else if (str.startsWith('@')) {
// scoped namespace
[, repo] = regEx(/(@.*?)(:|$)/).exec(str)!;
str = str.slice(repo.length);
if (!repo.includes('/')) {
repo += '/renovate-config';
}
if (str === '') {
presetName = 'default';
} else {
presetName = str.slice(1);
}
} else if (str.includes('//')) {
// non-scoped namespace with a subdirectory preset

// Validation
if (str.includes(':')) {
throw new Error(PRESET_PROHIBITED_SUBPRESET);
}
if (!nonScopedPresetWithSubdirRegex.test(str)) {
throw new Error(PRESET_INVALID);
}
({ repo, presetPath, presetName, tag } =
nonScopedPresetWithSubdirRegex.exec(str)!.groups!);
} else {
({ repo, presetName, tag } = gitPresetRegex.exec(str)!.groups!);

if (presetSource === 'npm' && !repo.startsWith('renovate-config-')) {
repo = `renovate-config-${repo}`;
}
if (!is.nonEmptyString(presetName)) {
presetName = 'default';
}
}

return {
presetSource,
presetPath,
repo,
presetName,
tag,
params,
};
}

export async function getPreset(
preset: string,
baseConfig?: RenovateConfig,
Expand Down
Loading
Loading