Skip to content
Snippets Groups Projects
Commit d27d35e5 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

feat: allow strings instead of lists (#665)

Updates definitions for schedule and package rules to allow strings to be massaged to lists - instead of erroring.

Closes #662
parent 88aaaccf
No related merge requests found
...@@ -65,6 +65,7 @@ const options = [ ...@@ -65,6 +65,7 @@ const options = [
name: 'schedule', name: 'schedule',
description: 'Times of day/week to renovate', description: 'Times of day/week to renovate',
type: 'list', type: 'list',
allowString: true,
cli: false, cli: false,
env: false, env: false,
}, },
...@@ -201,6 +202,7 @@ const options = [ ...@@ -201,6 +202,7 @@ const options = [
description: description:
'Package names to match. Valid only within `packageRules` object', 'Package names to match. Valid only within `packageRules` object',
type: 'list', type: 'list',
allowString: true,
stage: 'depType', stage: 'depType',
cli: false, cli: false,
env: false, env: false,
...@@ -210,6 +212,7 @@ const options = [ ...@@ -210,6 +212,7 @@ const options = [
description: description:
'Package names to exclude. Valid only within `packageRules` object', 'Package names to exclude. Valid only within `packageRules` object',
type: 'list', type: 'list',
allowString: true,
stage: 'depType', stage: 'depType',
cli: false, cli: false,
env: false, env: false,
...@@ -219,6 +222,7 @@ const options = [ ...@@ -219,6 +222,7 @@ const options = [
description: description:
'Package name patterns to match. Valid only within `packageRules` object.', 'Package name patterns to match. Valid only within `packageRules` object.',
type: 'list', type: 'list',
allowString: true,
stage: 'depType', stage: 'depType',
cli: false, cli: false,
env: false, env: false,
...@@ -228,6 +232,7 @@ const options = [ ...@@ -228,6 +232,7 @@ const options = [
description: description:
'Package name patterns to exclude. Valid only within `packageRules` object.', 'Package name patterns to exclude. Valid only within `packageRules` object.',
type: 'list', type: 'list',
allowString: true,
stage: 'depType', stage: 'depType',
cli: false, cli: false,
env: false, env: false,
......
const options = require('./definitions').getOptions();
const allowedStrings = [];
options.forEach(option => {
if (option.allowString) {
allowedStrings.push(option.name);
}
});
module.exports = {
massageConfig,
};
// Returns a massaged config
function massageConfig(config) {
const massagedConfig = { ...config };
for (const key of Object.keys(config)) {
const val = config[key];
if (allowedStrings.includes(key) && typeof val === 'string') {
massagedConfig[key] = [val];
} else if (isObject(val)) {
massagedConfig[key] = massageConfig(val);
}
}
return massagedConfig;
}
function isObject(obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}
...@@ -30,9 +30,6 @@ function migrateConfig(config, parentConfig) { ...@@ -30,9 +30,6 @@ function migrateConfig(config, parentConfig) {
isMigrated = true; isMigrated = true;
delete migratedConfig[key]; delete migratedConfig[key];
} }
} else if (key === 'schedule' && typeof val === 'string') {
isMigrated = true;
migratedConfig.schedule = [val];
} else if (key === 'packages') { } else if (key === 'packages') {
isMigrated = true; isMigrated = true;
migratedConfig.packageRules = migratedConfig.packages.map( migratedConfig.packageRules = migratedConfig.packages.map(
......
...@@ -4,6 +4,7 @@ const path = require('path'); ...@@ -4,6 +4,7 @@ const path = require('path');
const jsonValidator = require('json-dup-key-validator'); const jsonValidator = require('json-dup-key-validator');
const configParser = require('../../config'); const configParser = require('../../config');
const configMigration = require('../../config/migration'); const configMigration = require('../../config/migration');
const configMassage = require('../../config/massage');
const configValidation = require('../../config/validation'); const configValidation = require('../../config/validation');
// API // API
const githubApi = require('../../api/github'); const githubApi = require('../../api/github');
...@@ -108,13 +109,14 @@ function migrateAndValidate(config, input) { ...@@ -108,13 +109,14 @@ function migrateAndValidate(config, input) {
'Config migration necessary' 'Config migration necessary'
); );
} }
const { warnings, errors } = configValidation.validateConfig(migratedConfig); const massagedConfig = configMassage.massageConfig(migratedConfig);
const { warnings, errors } = configValidation.validateConfig(massagedConfig);
// istanbul ignore if // istanbul ignore if
if (warnings.length) { if (warnings.length) {
config.logger.debug({ warnings }, 'Found renovate.json warnings'); config.logger.debug({ warnings }, 'Found renovate config warnings');
} }
if (errors.length) { if (errors.length) {
config.logger.warn({ errors }, 'Found renovate.json errors'); config.logger.warn({ errors }, 'Found renovate config errors');
/* TODO #556 /* TODO #556
renovateJsonErrors.forEach(error => { renovateJsonErrors.forEach(error => {
config.errors.push( config.errors.push(
......
...@@ -19,9 +19,7 @@ Object { ...@@ -19,9 +19,7 @@ Object {
}, },
], ],
"prTitle": "some pr title", "prTitle": "some pr title",
"schedule": Array [ "schedule": "after 5pm",
"after 5pm",
],
"semanticPrefix": "fix(deps):", "semanticPrefix": "fix(deps):",
} }
`; `;
......
...@@ -160,7 +160,7 @@ describe('workers/repository/apis', () => { ...@@ -160,7 +160,7 @@ describe('workers/repository/apis', () => {
}); });
it('returns warning + error plus extended config if unknown keys', async () => { it('returns warning + error plus extended config if unknown keys', async () => {
config.api.getFileContent.mockReturnValueOnce( config.api.getFileContent.mockReturnValueOnce(
'{ "enabled": true, "foo": false, "maintainYarnLock": true }' '{ "enabled": true, "foo": false, "maintainYarnLock": true, "schedule": "before 5am", "minor": {} }'
); );
const returnConfig = await apis.mergeRenovateJson(config); const returnConfig = await apis.mergeRenovateJson(config);
expect(returnConfig.enabled).toBe(true); expect(returnConfig.enabled).toBe(true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment