2019-07-17 08:14:56 +00:00
|
|
|
import is from '@sindresorhus/is';
|
2019-08-23 13:46:31 +00:00
|
|
|
import later from 'later';
|
|
|
|
import { logger } from '../logger';
|
2020-03-02 11:06:16 +00:00
|
|
|
import { HostRule } from '../types';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { clone } from '../util/clone';
|
|
|
|
import { PackageRule, RenovateConfig } from './common';
|
|
|
|
import { RenovateOptions, getOptions } from './definitions';
|
2019-07-17 08:14:56 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
const options = getOptions();
|
2017-08-14 05:49:33 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
let optionTypes: Record<string, RenovateOptions['type']>;
|
2017-08-02 06:54:42 +00:00
|
|
|
|
|
|
|
const removedOptions = [
|
|
|
|
'maintainYarnLock',
|
2017-08-05 05:48:12 +00:00
|
|
|
'yarnCacheFolder',
|
2017-08-02 06:54:42 +00:00
|
|
|
'yarnMaintenanceBranchName',
|
|
|
|
'yarnMaintenanceCommitMessage',
|
|
|
|
'yarnMaintenancePrTitle',
|
|
|
|
'yarnMaintenancePrBody',
|
|
|
|
'groupBranchName',
|
|
|
|
'groupBranchName',
|
|
|
|
'groupCommitMessage',
|
|
|
|
'groupPrTitle',
|
|
|
|
'groupPrBody',
|
|
|
|
];
|
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
export interface MigratedConfig {
|
|
|
|
isMigrated: boolean;
|
|
|
|
migratedConfig: RenovateConfig;
|
|
|
|
}
|
|
|
|
|
2020-03-02 11:06:16 +00:00
|
|
|
interface MigratedRenovateConfig extends RenovateConfig {
|
|
|
|
endpoints?: HostRule[];
|
|
|
|
pathRules: PackageRule[];
|
|
|
|
packages: PackageRule[];
|
|
|
|
|
|
|
|
node?: RenovateConfig;
|
|
|
|
travis?: RenovateConfig;
|
|
|
|
}
|
|
|
|
|
2017-08-02 06:54:42 +00:00
|
|
|
// Returns a migrated config
|
2019-08-23 13:46:31 +00:00
|
|
|
export function migrateConfig(
|
|
|
|
config: RenovateConfig,
|
|
|
|
// TODO: remove any type
|
|
|
|
parentKey?: string | any
|
|
|
|
): MigratedConfig {
|
2018-03-08 06:28:06 +00:00
|
|
|
try {
|
|
|
|
if (!optionTypes) {
|
|
|
|
optionTypes = {};
|
2020-04-12 16:09:36 +00:00
|
|
|
options.forEach((option) => {
|
2018-03-08 06:28:06 +00:00
|
|
|
optionTypes[option.name] = option.type;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
let isMigrated = false;
|
2020-03-02 11:06:16 +00:00
|
|
|
const migratedConfig = clone(config) as MigratedRenovateConfig;
|
2018-04-30 06:21:48 +00:00
|
|
|
const depTypes = [
|
|
|
|
'dependencies',
|
|
|
|
'devDependencies',
|
2020-02-22 15:31:01 +00:00
|
|
|
'engines',
|
2018-04-30 06:21:48 +00:00
|
|
|
'optionalDependencies',
|
|
|
|
'peerDependencies',
|
|
|
|
];
|
2018-03-08 06:28:06 +00:00
|
|
|
for (const [key, val] of Object.entries(config)) {
|
|
|
|
if (removedOptions.includes(key)) {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig[key];
|
2018-04-29 21:07:39 +00:00
|
|
|
} else if (key === 'pathRules') {
|
|
|
|
isMigrated = true;
|
2018-06-04 18:07:22 +00:00
|
|
|
if (is.array(val)) {
|
2018-04-29 21:07:39 +00:00
|
|
|
migratedConfig.packageRules = migratedConfig.packageRules || [];
|
|
|
|
const migratedPathRules = migratedConfig.pathRules.map(
|
2020-04-12 16:09:36 +00:00
|
|
|
(p) => migrateConfig(p, key).migratedConfig
|
2018-04-29 21:07:39 +00:00
|
|
|
);
|
|
|
|
migratedConfig.packageRules = migratedPathRules.concat(
|
|
|
|
migratedConfig.packageRules
|
|
|
|
);
|
|
|
|
}
|
|
|
|
delete migratedConfig.pathRules;
|
2020-07-07 12:30:45 +00:00
|
|
|
} else if (key === 'suppressNotifications') {
|
|
|
|
if (is.nonEmptyArray(val) && val.includes('prEditNotification')) {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.suppressNotifications = migratedConfig.suppressNotifications.filter(
|
|
|
|
(item) => item !== 'prEditNotification'
|
|
|
|
);
|
|
|
|
}
|
2019-03-07 14:15:01 +00:00
|
|
|
} else if (key === 'gomodTidy') {
|
|
|
|
isMigrated = true;
|
|
|
|
if (val) {
|
|
|
|
migratedConfig.postUpdateOptions =
|
|
|
|
migratedConfig.postUpdateOptions || [];
|
|
|
|
migratedConfig.postUpdateOptions.push('gomodTidy');
|
|
|
|
}
|
|
|
|
delete migratedConfig.gomodTidy;
|
2019-05-21 11:20:09 +00:00
|
|
|
} else if (parentKey === 'hostRules' && key === 'platform') {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.hostType = val;
|
|
|
|
delete migratedConfig.platform;
|
2019-05-24 15:40:39 +00:00
|
|
|
} else if (parentKey === 'hostRules' && key === 'endpoint') {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.baseUrl = val;
|
|
|
|
delete migratedConfig.endpoint;
|
|
|
|
} else if (parentKey === 'hostRules' && key === 'host') {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.hostName = val;
|
|
|
|
delete migratedConfig.host;
|
2018-06-04 18:07:22 +00:00
|
|
|
} else if (key === 'packageFiles' && is.array(val)) {
|
2018-05-01 07:21:15 +00:00
|
|
|
isMigrated = true;
|
|
|
|
const fileList = [];
|
|
|
|
for (const packageFile of val) {
|
2018-06-04 18:07:22 +00:00
|
|
|
if (is.object(packageFile) && !is.array(packageFile)) {
|
2019-08-28 04:46:48 +00:00
|
|
|
fileList.push((packageFile as any).packageFile);
|
2018-05-01 07:21:15 +00:00
|
|
|
if (Object.keys(packageFile).length > 1) {
|
|
|
|
migratedConfig.packageRules = migratedConfig.packageRules || [];
|
2020-03-02 11:06:16 +00:00
|
|
|
const payload = migrateConfig(packageFile as RenovateConfig, key)
|
|
|
|
.migratedConfig;
|
2018-05-01 07:21:15 +00:00
|
|
|
for (const subrule of payload.packageRules || []) {
|
2019-08-28 04:46:48 +00:00
|
|
|
subrule.paths = [(packageFile as any).packageFile];
|
2018-05-01 07:21:15 +00:00
|
|
|
migratedConfig.packageRules.push(subrule);
|
|
|
|
}
|
|
|
|
delete payload.packageFile;
|
|
|
|
delete payload.packageRules;
|
|
|
|
if (Object.keys(payload).length) {
|
|
|
|
migratedConfig.packageRules.push({
|
|
|
|
...payload,
|
2019-08-28 04:46:48 +00:00
|
|
|
paths: [(packageFile as any).packageFile],
|
2018-05-01 07:21:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fileList.push(packageFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
migratedConfig.includePaths = fileList;
|
|
|
|
delete migratedConfig.packageFiles;
|
2018-04-30 06:21:48 +00:00
|
|
|
} else if (depTypes.includes(key)) {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.packageRules = migratedConfig.packageRules || [];
|
2020-03-02 11:06:16 +00:00
|
|
|
const depTypePackageRule = migrateConfig(val as RenovateConfig, key)
|
|
|
|
.migratedConfig;
|
2018-04-30 06:21:48 +00:00
|
|
|
depTypePackageRule.depTypeList = [key];
|
|
|
|
delete depTypePackageRule.packageRules;
|
|
|
|
migratedConfig.packageRules.push(depTypePackageRule);
|
|
|
|
delete migratedConfig[key];
|
feat: rangeStrategy (#1954)
This PR replaces the existing `pinVersions`, `upgradeInRange` and `versionStrategy` settings with a single one: `rangeStrategy`.
Previously:
- `pinVersions` could be `true` or `false`, but defaulted to `null`, which meant that Renovate would decide. `true` meant that Renovate would replace existing ranges like `^1.0.0` with an exact/pinned version such as `1.2.0`.
- `upgradeInRange` could be true or false, default to false. If `true`, it would mean Renovate would replace an existing range like `^1.0.0` with something like `^1.2.0`
- `versionStrategy` could be `replace` or `widen` and was mainly used for `peerDependencies` to widen existing ranges, e.g. from `^1.0.0` to `^1.0.0 || ^2.0.0`
It was possible to set conflicting settings, e.g. configuring `pinVersions=true` and `upgradeInRange=true`.
Now, we combine them into a single setting: `rangeStrategy`:
- `auto` = Renovate decides (this will be done on a manager-by-manager basis)
- `pin` = convert ranges to exact versions
- `bump` = same as `upgradeInRange` previously, e.g. bump the range even if the new version satisifies the existing range
- `replace` = Same as pinVersions === false && upgradeInRange === false, i.e. only replace the range if the new version falls outside it
- `widen` = Same as previous versionStrategy==='widen'
2018-05-17 05:16:13 +00:00
|
|
|
} else if (key === 'pinVersions') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.pinVersions;
|
|
|
|
if (val === true) {
|
|
|
|
migratedConfig.rangeStrategy = 'pin';
|
|
|
|
} else if (val === false) {
|
|
|
|
migratedConfig.rangeStrategy = 'replace';
|
|
|
|
}
|
2019-05-25 04:59:46 +00:00
|
|
|
} else if (key === 'gitFs') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.gitFs;
|
2020-02-22 15:31:50 +00:00
|
|
|
} else if (key === 'rebaseStalePrs') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.rebaseStalePrs;
|
|
|
|
if (!migratedConfig.rebaseWhen) {
|
2020-03-17 11:15:22 +00:00
|
|
|
if (val === null) {
|
|
|
|
migratedConfig.rebaseWhen = 'auto';
|
|
|
|
}
|
|
|
|
if (val === true) {
|
|
|
|
migratedConfig.rebaseWhen = 'behind-base-branch';
|
|
|
|
}
|
|
|
|
if (val === false) {
|
|
|
|
migratedConfig.rebaseWhen = 'conflicted';
|
|
|
|
}
|
2020-02-22 15:31:50 +00:00
|
|
|
}
|
|
|
|
} else if (key === 'rebaseConflictedPrs') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.rebaseConflictedPrs;
|
2020-03-17 11:15:22 +00:00
|
|
|
if (val === false) {
|
|
|
|
migratedConfig.rebaseWhen = 'never';
|
|
|
|
}
|
2018-11-16 11:16:37 +00:00
|
|
|
} else if (key === 'exposeEnv') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.exposeEnv;
|
|
|
|
if (val === true) {
|
|
|
|
migratedConfig.trustLevel = 'high';
|
|
|
|
} else if (val === false) {
|
|
|
|
migratedConfig.trustLevel = 'low';
|
|
|
|
}
|
feat: rangeStrategy (#1954)
This PR replaces the existing `pinVersions`, `upgradeInRange` and `versionStrategy` settings with a single one: `rangeStrategy`.
Previously:
- `pinVersions` could be `true` or `false`, but defaulted to `null`, which meant that Renovate would decide. `true` meant that Renovate would replace existing ranges like `^1.0.0` with an exact/pinned version such as `1.2.0`.
- `upgradeInRange` could be true or false, default to false. If `true`, it would mean Renovate would replace an existing range like `^1.0.0` with something like `^1.2.0`
- `versionStrategy` could be `replace` or `widen` and was mainly used for `peerDependencies` to widen existing ranges, e.g. from `^1.0.0` to `^1.0.0 || ^2.0.0`
It was possible to set conflicting settings, e.g. configuring `pinVersions=true` and `upgradeInRange=true`.
Now, we combine them into a single setting: `rangeStrategy`:
- `auto` = Renovate decides (this will be done on a manager-by-manager basis)
- `pin` = convert ranges to exact versions
- `bump` = same as `upgradeInRange` previously, e.g. bump the range even if the new version satisifies the existing range
- `replace` = Same as pinVersions === false && upgradeInRange === false, i.e. only replace the range if the new version falls outside it
- `widen` = Same as previous versionStrategy==='widen'
2018-05-17 05:16:13 +00:00
|
|
|
} else if (key === 'upgradeInRange') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.upgradeInRange;
|
|
|
|
if (val === true) {
|
|
|
|
migratedConfig.rangeStrategy = 'bump';
|
|
|
|
}
|
|
|
|
} else if (key === 'versionStrategy') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.versionStrategy;
|
|
|
|
if (val === 'widen') {
|
|
|
|
migratedConfig.rangeStrategy = 'widen';
|
|
|
|
}
|
2020-03-02 11:06:16 +00:00
|
|
|
} else if (key === 'semanticPrefix' && is.string(val)) {
|
2018-03-08 06:28:06 +00:00
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.semanticPrefix;
|
2020-03-02 11:06:16 +00:00
|
|
|
let [text] = val.split(':') as any; // TODO: fixme
|
2018-03-08 06:28:06 +00:00
|
|
|
text = text.split('(');
|
|
|
|
[migratedConfig.semanticCommitType] = text;
|
|
|
|
if (text.length > 1) {
|
|
|
|
[migratedConfig.semanticCommitScope] = text[1].split(')');
|
|
|
|
} else {
|
|
|
|
migratedConfig.semanticCommitScope = null;
|
2018-03-08 05:02:16 +00:00
|
|
|
}
|
2018-06-04 18:07:22 +00:00
|
|
|
} else if (key === 'extends' && is.array(val)) {
|
2018-03-08 06:28:06 +00:00
|
|
|
for (let i = 0; i < val.length; i += 1) {
|
|
|
|
if (val[i] === 'config:application' || val[i] === ':js-app') {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.extends[i] = 'config:js-app';
|
|
|
|
} else if (val[i] === ':library' || val[i] === 'config:library') {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.extends[i] = 'config:js-lib';
|
|
|
|
}
|
|
|
|
}
|
2020-02-18 07:34:10 +00:00
|
|
|
} else if (key === 'versionScheme') {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.versioning = val;
|
|
|
|
delete migratedConfig.versionScheme;
|
2019-05-12 04:46:16 +00:00
|
|
|
} else if (
|
|
|
|
key === 'automergeType' &&
|
|
|
|
is.string(val) &&
|
|
|
|
val.startsWith('branch-')
|
|
|
|
) {
|
2018-06-26 11:51:50 +00:00
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.automergeType = 'branch';
|
2018-03-08 06:28:06 +00:00
|
|
|
} else if (key === 'automergeMinor') {
|
|
|
|
isMigrated = true;
|
2018-03-08 06:12:31 +00:00
|
|
|
migratedConfig.minor = migratedConfig.minor || {};
|
2018-03-08 06:28:06 +00:00
|
|
|
migratedConfig.minor.automerge = val == true; // eslint-disable-line eqeqeq
|
|
|
|
delete migratedConfig[key];
|
|
|
|
} else if (key === 'automergeMajor') {
|
|
|
|
isMigrated = true;
|
2018-03-08 06:12:31 +00:00
|
|
|
migratedConfig.major = migratedConfig.major || {};
|
2018-03-08 06:28:06 +00:00
|
|
|
migratedConfig.major.automerge = val == true; // eslint-disable-line eqeqeq
|
|
|
|
delete migratedConfig[key];
|
2018-05-17 05:33:59 +00:00
|
|
|
} else if (key === 'multipleMajorPrs') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.multipleMajorPrs;
|
|
|
|
migratedConfig.separateMultipleMajor = val;
|
2020-03-02 11:06:16 +00:00
|
|
|
} else if (key === 'renovateFork' && is.boolean(val)) {
|
2018-12-31 05:46:00 +00:00
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.renovateFork;
|
|
|
|
migratedConfig.includeForks = val;
|
2018-05-17 05:36:13 +00:00
|
|
|
} else if (key === 'separateMajorReleases') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.separateMultipleMajor;
|
|
|
|
migratedConfig.separateMajorMinor = val;
|
2018-05-17 05:40:29 +00:00
|
|
|
} else if (key === 'separatePatchReleases') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.separatePatchReleases;
|
|
|
|
migratedConfig.separateMinorPatch = val;
|
2018-03-08 06:28:06 +00:00
|
|
|
} else if (key === 'automergePatch') {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.patch = migratedConfig.patch || {};
|
|
|
|
migratedConfig.patch.automerge = val == true; // eslint-disable-line eqeqeq
|
|
|
|
delete migratedConfig[key];
|
|
|
|
} else if (key === 'ignoreNodeModules') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.ignoreNodeModules;
|
|
|
|
migratedConfig.ignorePaths = val ? ['node_modules/'] : [];
|
|
|
|
} else if (
|
|
|
|
key === 'automerge' &&
|
2018-06-04 18:07:22 +00:00
|
|
|
is.string(val) &&
|
2018-06-04 18:44:32 +00:00
|
|
|
['none', 'patch', 'minor', 'any'].includes(val)
|
2018-03-08 06:28:06 +00:00
|
|
|
) {
|
|
|
|
delete migratedConfig.automerge;
|
|
|
|
isMigrated = true;
|
|
|
|
if (val === 'none') {
|
|
|
|
migratedConfig.automerge = false;
|
|
|
|
} else if (val === 'patch') {
|
|
|
|
migratedConfig.patch = migratedConfig.patch || {};
|
|
|
|
migratedConfig.patch.automerge = true;
|
|
|
|
migratedConfig.minor = migratedConfig.minor || {};
|
|
|
|
migratedConfig.minor.automerge = false;
|
|
|
|
migratedConfig.major = migratedConfig.major || {};
|
|
|
|
migratedConfig.major.automerge = false;
|
|
|
|
} else if (val === 'minor') {
|
|
|
|
migratedConfig.minor = migratedConfig.minor || {};
|
|
|
|
migratedConfig.minor.automerge = true;
|
|
|
|
migratedConfig.major = migratedConfig.major || {};
|
|
|
|
migratedConfig.major.automerge = false;
|
2020-03-07 10:27:10 +00:00
|
|
|
} /* istanbul ignore else: we can never go to else */ else if (
|
|
|
|
val === 'any'
|
|
|
|
) {
|
2018-03-08 06:28:06 +00:00
|
|
|
migratedConfig.automerge = true;
|
|
|
|
}
|
|
|
|
} else if (key === 'packages') {
|
|
|
|
isMigrated = true;
|
2018-04-29 21:07:39 +00:00
|
|
|
migratedConfig.packageRules = migratedConfig.packageRules || [];
|
|
|
|
migratedConfig.packageRules = migratedConfig.packageRules.concat(
|
2020-04-12 16:09:36 +00:00
|
|
|
migratedConfig.packages.map(
|
|
|
|
(p) => migrateConfig(p, key).migratedConfig
|
|
|
|
)
|
2018-03-08 06:28:06 +00:00
|
|
|
);
|
|
|
|
delete migratedConfig.packages;
|
|
|
|
} else if (key === 'excludedPackageNames') {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.excludePackageNames = val;
|
|
|
|
delete migratedConfig.excludedPackageNames;
|
|
|
|
} else if (key === 'packageName') {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.packageNames = [val];
|
|
|
|
delete migratedConfig.packageName;
|
|
|
|
} else if (key === 'packagePattern') {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig.packagePatterns = [val];
|
|
|
|
delete migratedConfig.packagePattern;
|
|
|
|
} else if (key === 'baseBranch') {
|
|
|
|
isMigrated = true;
|
2018-06-04 18:07:22 +00:00
|
|
|
migratedConfig.baseBranches = is.array(val) ? val : [val];
|
2018-03-08 06:28:06 +00:00
|
|
|
delete migratedConfig.baseBranch;
|
2018-10-05 07:59:32 +00:00
|
|
|
} else if (key === 'schedule' && val) {
|
2018-03-08 06:28:06 +00:00
|
|
|
// massage to array first
|
2020-03-02 11:06:16 +00:00
|
|
|
const schedules = is.string(val) ? [val] : [...(val as string[])];
|
2018-03-08 06:28:06 +00:00
|
|
|
// split 'and'
|
2018-12-05 04:39:24 +00:00
|
|
|
const schedulesLength = schedules.length;
|
|
|
|
for (let i = 0; i < schedulesLength; i += 1) {
|
2018-03-08 06:28:06 +00:00
|
|
|
if (
|
|
|
|
schedules[i].includes(' and ') &&
|
|
|
|
schedules[i].includes('before ') &&
|
|
|
|
schedules[i].includes('after ')
|
|
|
|
) {
|
|
|
|
const parsedSchedule = later.parse.text(
|
|
|
|
// We need to massage short hours first before we can parse it
|
|
|
|
schedules[i].replace(/( \d?\d)((a|p)m)/g, '$1:00$2')
|
|
|
|
).schedules[0];
|
|
|
|
// Only migrate if the after time is greater than before, e.g. "after 10pm and before 5am"
|
|
|
|
if (
|
|
|
|
parsedSchedule &&
|
2018-07-20 06:40:43 +00:00
|
|
|
parsedSchedule.t_a &&
|
|
|
|
parsedSchedule.t_b &&
|
2018-03-08 06:28:06 +00:00
|
|
|
parsedSchedule.t_a[0] > parsedSchedule.t_b[0]
|
|
|
|
) {
|
|
|
|
isMigrated = true;
|
|
|
|
const toSplit = schedules[i];
|
|
|
|
schedules[i] = toSplit
|
2017-09-01 09:27:54 +00:00
|
|
|
.replace(
|
2018-12-05 04:39:24 +00:00
|
|
|
/^(.*?)(after|before) (.*?) and (after|before) (.*?)( |$)(.*)/,
|
|
|
|
'$1$2 $3 $7'
|
2017-09-01 09:27:54 +00:00
|
|
|
)
|
2018-03-08 06:28:06 +00:00
|
|
|
.trim();
|
|
|
|
schedules.push(
|
|
|
|
toSplit
|
|
|
|
.replace(
|
2018-12-05 04:39:24 +00:00
|
|
|
/^(.*?)(after|before) (.*?) and (after|before) (.*?)( |$)(.*)/,
|
|
|
|
'$1$4 $5 $7'
|
2018-03-08 06:28:06 +00:00
|
|
|
)
|
|
|
|
.trim()
|
|
|
|
);
|
|
|
|
}
|
2018-03-08 05:02:16 +00:00
|
|
|
}
|
2017-10-14 05:03:44 +00:00
|
|
|
}
|
2018-03-08 06:28:06 +00:00
|
|
|
for (let i = 0; i < schedules.length; i += 1) {
|
2018-06-04 18:44:32 +00:00
|
|
|
if (schedules[i].includes('on the last day of the month')) {
|
2018-03-08 06:28:06 +00:00
|
|
|
isMigrated = true;
|
|
|
|
schedules[i] = schedules[i].replace(
|
|
|
|
'on the last day of the month',
|
|
|
|
'on the first day of the month'
|
|
|
|
);
|
|
|
|
}
|
2018-06-04 18:44:32 +00:00
|
|
|
if (schedules[i].includes('on every weekday')) {
|
2018-03-08 06:28:06 +00:00
|
|
|
isMigrated = true;
|
|
|
|
schedules[i] = schedules[i].replace(
|
|
|
|
'on every weekday',
|
|
|
|
'every weekday'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (schedules[i].endsWith(' every day')) {
|
|
|
|
isMigrated = true;
|
|
|
|
schedules[i] = schedules[i].replace(' every day', '');
|
|
|
|
}
|
|
|
|
if (
|
2020-03-02 11:06:16 +00:00
|
|
|
/every (mon|tues|wednes|thurs|fri|satur|sun)day$/.test(schedules[i])
|
2018-03-08 06:28:06 +00:00
|
|
|
) {
|
|
|
|
isMigrated = true;
|
|
|
|
schedules[i] = schedules[i].replace(/every ([a-z]*day)$/, 'on $1');
|
|
|
|
}
|
|
|
|
if (schedules[i].endsWith('days')) {
|
|
|
|
isMigrated = true;
|
|
|
|
schedules[i] = schedules[i].replace('days', 'day');
|
|
|
|
}
|
2017-08-23 09:50:05 +00:00
|
|
|
}
|
2018-03-08 06:28:06 +00:00
|
|
|
if (isMigrated) {
|
2018-06-04 18:07:22 +00:00
|
|
|
if (is.string(val) && schedules.length === 1) {
|
2020-03-02 11:06:16 +00:00
|
|
|
[migratedConfig.schedule] = schedules as any; // TODO: fixme
|
2018-03-08 06:28:06 +00:00
|
|
|
} else {
|
|
|
|
migratedConfig.schedule = schedules;
|
|
|
|
}
|
2017-08-02 12:05:45 +00:00
|
|
|
}
|
2018-06-04 18:44:32 +00:00
|
|
|
} else if (is.string(val) && val.startsWith('{{semanticPrefix}}')) {
|
2018-04-17 10:08:13 +00:00
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig[key] = val.replace(
|
|
|
|
'{{semanticPrefix}}',
|
2018-04-17 12:40:00 +00:00
|
|
|
'{{#if semanticCommitType}}{{semanticCommitType}}{{#if semanticCommitScope}}({{semanticCommitScope}}){{/if}}: {{/if}}'
|
2018-04-17 10:08:13 +00:00
|
|
|
);
|
2018-06-04 18:07:22 +00:00
|
|
|
} else if (key === 'depTypes' && is.array(val)) {
|
2020-04-12 16:09:36 +00:00
|
|
|
val.forEach((depType) => {
|
2018-06-04 18:07:22 +00:00
|
|
|
if (is.object(depType) && !is.array(depType)) {
|
2019-08-28 04:46:48 +00:00
|
|
|
const depTypeName = (depType as any).depType;
|
2018-03-08 06:28:06 +00:00
|
|
|
if (depTypeName) {
|
2018-04-29 21:07:39 +00:00
|
|
|
migratedConfig.packageRules = migratedConfig.packageRules || [];
|
2020-03-02 11:06:16 +00:00
|
|
|
const newPackageRule = migrateConfig(
|
|
|
|
depType as RenovateConfig,
|
|
|
|
key
|
|
|
|
).migratedConfig;
|
2018-04-29 21:07:39 +00:00
|
|
|
delete newPackageRule.depType;
|
|
|
|
newPackageRule.depTypeList = [depTypeName];
|
|
|
|
migratedConfig.packageRules.push(newPackageRule);
|
2018-03-08 06:28:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.depTypes;
|
2019-03-31 06:01:06 +00:00
|
|
|
} else if (optionTypes[key] === 'object' && is.boolean(val)) {
|
2018-03-08 06:28:06 +00:00
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig[key] = { enabled: val };
|
|
|
|
} else if (optionTypes[key] === 'boolean') {
|
|
|
|
if (val === 'true') {
|
|
|
|
migratedConfig[key] = true;
|
|
|
|
} else if (val === 'false') {
|
|
|
|
migratedConfig[key] = false;
|
2018-03-08 06:12:31 +00:00
|
|
|
}
|
2018-03-08 06:28:06 +00:00
|
|
|
} else if (
|
|
|
|
optionTypes[key] === 'string' &&
|
2018-06-04 18:07:22 +00:00
|
|
|
is.array(val) &&
|
2018-03-08 06:28:06 +00:00
|
|
|
val.length === 1
|
|
|
|
) {
|
|
|
|
migratedConfig[key] = `${val[0]}`;
|
2020-03-02 11:06:16 +00:00
|
|
|
} else if (key === 'node' && (val as RenovateConfig).enabled === true) {
|
2018-03-08 06:28:06 +00:00
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.node.enabled;
|
|
|
|
migratedConfig.travis = migratedConfig.travis || {};
|
|
|
|
migratedConfig.travis.enabled = true;
|
|
|
|
if (!Object.keys(migratedConfig.node).length) {
|
|
|
|
delete migratedConfig.node;
|
2018-03-08 06:12:31 +00:00
|
|
|
} else {
|
2019-05-21 11:20:09 +00:00
|
|
|
const subMigrate = migrateConfig(migratedConfig.node, key);
|
2018-03-08 06:28:06 +00:00
|
|
|
migratedConfig.node = subMigrate.migratedConfig;
|
2018-03-08 06:12:31 +00:00
|
|
|
}
|
2018-06-04 18:07:22 +00:00
|
|
|
} else if (is.array(val)) {
|
2018-04-29 21:07:39 +00:00
|
|
|
const newArray = [];
|
2020-03-02 11:06:16 +00:00
|
|
|
for (const item of migratedConfig[key] as unknown[]) {
|
2018-06-04 18:07:22 +00:00
|
|
|
if (is.object(item) && !is.array(item)) {
|
2020-03-02 11:06:16 +00:00
|
|
|
const arrMigrate = migrateConfig(item as RenovateConfig, key);
|
2018-04-29 21:07:39 +00:00
|
|
|
newArray.push(arrMigrate.migratedConfig);
|
2018-03-08 06:28:06 +00:00
|
|
|
if (arrMigrate.isMigrated) {
|
|
|
|
isMigrated = true;
|
|
|
|
}
|
|
|
|
} else {
|
2018-04-29 21:07:39 +00:00
|
|
|
newArray.push(item);
|
2018-03-08 06:12:31 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-29 21:07:39 +00:00
|
|
|
migratedConfig[key] = newArray;
|
2018-06-04 18:07:22 +00:00
|
|
|
} else if (is.object(val)) {
|
2020-03-02 11:06:16 +00:00
|
|
|
const subMigrate = migrateConfig(
|
|
|
|
migratedConfig[key] as RenovateConfig,
|
|
|
|
key
|
|
|
|
);
|
2018-06-04 18:07:22 +00:00
|
|
|
if (subMigrate.isMigrated) {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig[key] = subMigrate.migratedConfig;
|
|
|
|
}
|
2018-06-04 03:48:20 +00:00
|
|
|
} else if (
|
2018-09-21 03:43:51 +00:00
|
|
|
key.startsWith('commitMessage') &&
|
2020-03-02 11:06:16 +00:00
|
|
|
is.string(val) &&
|
2018-06-04 03:48:20 +00:00
|
|
|
(val.includes('currentVersion') || val.includes('newVersion'))
|
|
|
|
) {
|
|
|
|
isMigrated = true;
|
|
|
|
migratedConfig[key] = val
|
|
|
|
.replace(/currentVersion/g, 'currentValue')
|
|
|
|
.replace(/newVersion/g, 'newValue')
|
|
|
|
.replace(/newValueMajor/g, 'newMajor')
|
|
|
|
.replace(/newValueMinor/g, 'newMinor');
|
2018-12-09 10:39:35 +00:00
|
|
|
} else if (key === 'raiseDeprecationWarnings') {
|
|
|
|
isMigrated = true;
|
|
|
|
delete migratedConfig.raiseDeprecationWarnings;
|
|
|
|
if (val === false) {
|
2018-12-09 12:17:37 +00:00
|
|
|
migratedConfig.suppressNotifications =
|
|
|
|
migratedConfig.suppressNotifications || [];
|
2018-12-09 10:39:35 +00:00
|
|
|
migratedConfig.suppressNotifications.push('deprecationWarningIssues');
|
|
|
|
}
|
2017-08-18 17:47:13 +00:00
|
|
|
}
|
2017-08-02 06:54:42 +00:00
|
|
|
}
|
2018-09-12 10:16:17 +00:00
|
|
|
if (migratedConfig.endpoints) {
|
|
|
|
migratedConfig.hostRules = migratedConfig.endpoints;
|
|
|
|
delete migratedConfig.endpoints;
|
|
|
|
isMigrated = true;
|
|
|
|
}
|
2018-03-08 06:28:06 +00:00
|
|
|
return { isMigrated, migratedConfig };
|
|
|
|
} catch (err) /* istanbul ignore next */ {
|
|
|
|
logger.debug({ config }, 'migrateConfig() error');
|
|
|
|
throw err;
|
2017-08-02 06:54:42 +00:00
|
|
|
}
|
|
|
|
}
|