mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 15:06:27 +00:00
feat(config): better config migration (#9493)
This commit is contained in:
parent
45739cddfd
commit
c4463c69f9
10 changed files with 64 additions and 49 deletions
|
@ -95,6 +95,7 @@ Object {
|
||||||
"dependencyDashboardTitle": "foo",
|
"dependencyDashboardTitle": "foo",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"extends": Array [
|
"extends": Array [
|
||||||
|
":automergeBranch",
|
||||||
"config:js-app",
|
"config:js-app",
|
||||||
"config:js-lib",
|
"config:js-lib",
|
||||||
":dependencyDashboard",
|
":dependencyDashboard",
|
||||||
|
|
|
@ -30,7 +30,13 @@ describe(getName(__filename), () => {
|
||||||
compatibility: {
|
compatibility: {
|
||||||
python: '3.7',
|
python: '3.7',
|
||||||
},
|
},
|
||||||
extends: [':js-app', 'config:library', ':masterIssue'],
|
extends: [
|
||||||
|
':automergeBranchMergeCommit',
|
||||||
|
'default:js-app',
|
||||||
|
'config:library',
|
||||||
|
':masterIssue',
|
||||||
|
'helpers:oddIsUnstable',
|
||||||
|
],
|
||||||
maintainYarnLock: true,
|
maintainYarnLock: true,
|
||||||
onboarding: 'false' as never,
|
onboarding: 'false' as never,
|
||||||
multipleMajorPrs: true,
|
multipleMajorPrs: true,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { logger } from '../logger';
|
||||||
import type { HostRule } from '../types';
|
import type { HostRule } from '../types';
|
||||||
import { clone } from '../util/clone';
|
import { clone } from '../util/clone';
|
||||||
import { getOptions } from './definitions';
|
import { getOptions } from './definitions';
|
||||||
|
import { removedPresets } from './presets/common';
|
||||||
import type { PackageRule, RenovateConfig, RenovateOptions } from './types';
|
import type { PackageRule, RenovateConfig, RenovateOptions } from './types';
|
||||||
import { mergeChildConfig } from './utils';
|
import { mergeChildConfig } from './utils';
|
||||||
|
|
||||||
|
@ -245,22 +246,15 @@ export function migrateConfig(
|
||||||
}
|
}
|
||||||
const presets = migratedConfig.extends;
|
const presets = migratedConfig.extends;
|
||||||
for (let i = 0; i < presets.length; i += 1) {
|
for (let i = 0; i < presets.length; i += 1) {
|
||||||
let preset = presets[i];
|
const preset = presets[i];
|
||||||
if (is.string(preset)) {
|
if (is.string(preset)) {
|
||||||
if (preset === 'config:application' || preset === ':js-app') {
|
const newPreset = removedPresets[preset];
|
||||||
preset = 'config:js-app';
|
if (newPreset !== undefined) {
|
||||||
} else if (preset === ':library' || preset === 'config:library') {
|
presets[i] = newPreset;
|
||||||
preset = 'config:js-lib';
|
|
||||||
} else if (preset.startsWith(':masterIssue')) {
|
|
||||||
preset = preset.replace('masterIssue', 'dependencyDashboard');
|
|
||||||
} else if (
|
|
||||||
[':unpublishSafe', 'default:unpublishSafe'].includes(preset)
|
|
||||||
) {
|
|
||||||
preset = 'npm:unpublishSafe';
|
|
||||||
}
|
}
|
||||||
presets[i] = preset;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
migratedConfig.extends = migratedConfig.extends.filter(Boolean);
|
||||||
} else if (key === 'unpublishSafe') {
|
} else if (key === 'unpublishSafe') {
|
||||||
if (val === true) {
|
if (val === true) {
|
||||||
migratedConfig.extends = migratedConfig.extends || [];
|
migratedConfig.extends = migratedConfig.extends || [];
|
||||||
|
|
|
@ -46,9 +46,7 @@ Object {
|
||||||
],
|
],
|
||||||
"packageRules": Array [
|
"packageRules": Array [
|
||||||
Object {
|
Object {
|
||||||
"extends": Array [
|
"extends": Array [],
|
||||||
"",
|
|
||||||
],
|
|
||||||
"groupName": "{{arg1}}",
|
"groupName": "{{arg1}}",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -67,6 +65,15 @@ exports[`config/presets/index getPreset handles preset not found 2`] = `undefine
|
||||||
|
|
||||||
exports[`config/presets/index getPreset handles preset not found 3`] = `undefined`;
|
exports[`config/presets/index getPreset handles preset not found 3`] = `undefined`;
|
||||||
|
|
||||||
|
exports[`config/presets/index getPreset handles removed presets with a migration 1`] = `
|
||||||
|
Object {
|
||||||
|
"dependencyDashboard": true,
|
||||||
|
"description": Array [
|
||||||
|
"Enable Renovate Dependency Dashboard creation",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`config/presets/index getPreset handles throw errors 1`] = `undefined`;
|
exports[`config/presets/index getPreset handles throw errors 1`] = `undefined`;
|
||||||
|
|
||||||
exports[`config/presets/index getPreset handles throw errors 2`] = `undefined`;
|
exports[`config/presets/index getPreset handles throw errors 2`] = `undefined`;
|
||||||
|
|
23
lib/config/presets/common.ts
Normal file
23
lib/config/presets/common.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
export const removedPresets = {
|
||||||
|
':automergeBranchMergeCommit': ':automergeBranch',
|
||||||
|
':automergeBranchPush': ':automergeBranch',
|
||||||
|
':base': 'config:base',
|
||||||
|
':app': 'config:js-app',
|
||||||
|
':js-app': 'config:js-app',
|
||||||
|
':library': 'config:js-lib',
|
||||||
|
':masterIssue': ':dependencyDashboard',
|
||||||
|
':masterIssueApproval': ':dependencyDashboardApproval',
|
||||||
|
':unpublishSafe': 'npm:unpublishSafe',
|
||||||
|
'config:application': 'config:js-app',
|
||||||
|
'config:base-js': 'config:base',
|
||||||
|
'config:library': 'config:js-lib',
|
||||||
|
'default:automergeBranchMergeCommit': ':automergeBranch',
|
||||||
|
'default:automergeBranchPush': ':automergeBranch',
|
||||||
|
'default:base': 'config:base',
|
||||||
|
'default:app': 'config:js-app',
|
||||||
|
'default:js-app': 'config:js-app',
|
||||||
|
'default:library': 'config:js-lib',
|
||||||
|
'default:unpublishSafe': 'npm:unpublishSafe',
|
||||||
|
'helpers:oddIsUnstable': null,
|
||||||
|
'helpers:oddIsUnstablePackages': null,
|
||||||
|
};
|
|
@ -392,6 +392,14 @@ describe(getName(__filename), () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('getPreset', () => {
|
describe('getPreset', () => {
|
||||||
|
it('handles removed presets with a migration', async () => {
|
||||||
|
const res = await presets.getPreset(':masterIssue', {});
|
||||||
|
expect(res).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
it('handles removed presets with no migration', async () => {
|
||||||
|
const res = await presets.getPreset('helpers:oddIsUnstable', {});
|
||||||
|
expect(res).toEqual({});
|
||||||
|
});
|
||||||
it('gets linters', async () => {
|
it('gets linters', async () => {
|
||||||
const res = await presets.getPreset('packages:linters', {});
|
const res = await presets.getPreset('packages:linters', {});
|
||||||
expect(res).toMatchSnapshot();
|
expect(res).toMatchSnapshot();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import * as massage from '../massage';
|
||||||
import * as migration from '../migration';
|
import * as migration from '../migration';
|
||||||
import type { GlobalConfig, RenovateConfig } from '../types';
|
import type { GlobalConfig, RenovateConfig } from '../types';
|
||||||
import { mergeChildConfig } from '../utils';
|
import { mergeChildConfig } from '../utils';
|
||||||
|
import { removedPresets } from './common';
|
||||||
import * as gitea from './gitea';
|
import * as gitea from './gitea';
|
||||||
import * as github from './github';
|
import * as github from './github';
|
||||||
import * as gitlab from './gitlab';
|
import * as gitlab from './gitlab';
|
||||||
|
@ -165,6 +166,14 @@ export async function getPreset(
|
||||||
baseConfig?: RenovateConfig
|
baseConfig?: RenovateConfig
|
||||||
): Promise<RenovateConfig> {
|
): Promise<RenovateConfig> {
|
||||||
logger.trace(`getPreset(${preset})`);
|
logger.trace(`getPreset(${preset})`);
|
||||||
|
// Check if the preset has been removed or replaced
|
||||||
|
const newPreset = removedPresets[preset];
|
||||||
|
if (newPreset) {
|
||||||
|
return getPreset(newPreset, baseConfig);
|
||||||
|
}
|
||||||
|
if (newPreset === null) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
const {
|
const {
|
||||||
presetSource,
|
presetSource,
|
||||||
packageName,
|
packageName,
|
||||||
|
|
|
@ -21,10 +21,6 @@ export const presets: Record<string, Preset> = {
|
||||||
'workarounds:all',
|
'workarounds:all',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
'base-js': {
|
|
||||||
description: 'Base configuration for Javascript (deprecated)',
|
|
||||||
extends: ['config:base'],
|
|
||||||
},
|
|
||||||
'js-app': {
|
'js-app': {
|
||||||
description: 'Default configuration for webapps',
|
description: 'Default configuration for webapps',
|
||||||
extends: ['config:base', ':pinAllExceptPeerDependencies'],
|
extends: ['config:base', ':pinAllExceptPeerDependencies'],
|
||||||
|
|
|
@ -304,16 +304,6 @@ export const presets: Record<string, Preset> = {
|
||||||
'If automerging, push the new commit directly to base branch (no PR)',
|
'If automerging, push the new commit directly to base branch (no PR)',
|
||||||
automergeType: 'branch',
|
automergeType: 'branch',
|
||||||
},
|
},
|
||||||
automergeBranchMergeCommit: {
|
|
||||||
description:
|
|
||||||
'If automerging, perform a merge-commit on branch (no PR) - deprecated, use :automergeBranch instead',
|
|
||||||
automergeType: 'branch-merge-commit',
|
|
||||||
},
|
|
||||||
automergeBranchPush: {
|
|
||||||
description:
|
|
||||||
'If automerging, push the new commit directly to base branch (no PR) - deprecated, use :automergeBranch instead',
|
|
||||||
automergeType: 'branch-push',
|
|
||||||
},
|
|
||||||
automergePr: {
|
automergePr: {
|
||||||
description: 'Raise a PR first before any automerging',
|
description: 'Raise a PR first before any automerging',
|
||||||
automergeType: 'pr',
|
automergeType: 'pr',
|
||||||
|
@ -572,18 +562,6 @@ export const presets: Record<string, Preset> = {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
base: {
|
|
||||||
description: 'deprecated alias for config:base',
|
|
||||||
extends: ['config:base'],
|
|
||||||
},
|
|
||||||
app: {
|
|
||||||
description: 'deprecated alias for config:js-app',
|
|
||||||
extends: ['config:js-app'],
|
|
||||||
},
|
|
||||||
library: {
|
|
||||||
description: 'deprecated alias for config:js-lib',
|
|
||||||
extends: ['config:js-lib'],
|
|
||||||
},
|
|
||||||
disablePrControls: {
|
disablePrControls: {
|
||||||
description: 'Remove the checkbox controls from PRs',
|
description: 'Remove the checkbox controls from PRs',
|
||||||
prBodyTemplate:
|
prBodyTemplate:
|
||||||
|
|
|
@ -10,13 +10,6 @@ export const presets: Record<string, Preset> = {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
oddIsUnstable: {
|
|
||||||
description: 'DEPRECATED: Odd version numbers are classified as unstable',
|
|
||||||
},
|
|
||||||
oddIsUnstablePackages: {
|
|
||||||
description:
|
|
||||||
'DEPRECATED: Preconfigure dependencies where an odd major version indicates unstable (Docker-only)',
|
|
||||||
},
|
|
||||||
followTypescriptNext: {
|
followTypescriptNext: {
|
||||||
description:
|
description:
|
||||||
'Keep <typescript> version in sync with the <code>next</code> tag',
|
'Keep <typescript> version in sync with the <code>next</code> tag',
|
||||||
|
|
Loading…
Reference in a new issue