refactor(config): change definitions to match schema (#3434)

This commit is contained in:
Rishabh Jain 2019-03-31 11:31:06 +05:30 коммит произвёл Rhys Arkins
Родитель fd35e5ba3d
Коммит b7e5546788
8 изменённых файлов: 93 добавлений и 101 удалений

Просмотреть файл

@ -2,15 +2,6 @@ const fs = require('fs');
const upath = require('upath');
const { getOptions } = require('../lib/config/definitions');
const types = {
list: 'array',
json: 'object',
object: 'object',
integer: 'integer',
string: 'string',
boolean: 'boolean',
};
const schema = {
title: 'JSON schema for Renovate config files (https://renovatebot.com/)',
$schema: 'http://json-schema.org/draft-04/schema#',
@ -25,11 +16,11 @@ function createSingleConfig(option) {
if (option.description) {
temp.description = option.description;
}
temp.type = types[option.type];
temp.type = option.type;
if (temp.type === 'array') {
if (option.subType) {
temp.items = {
type: types[option.subType],
type: option.subType,
};
if (option.format) {
temp.items.format = option.format;

Просмотреть файл

@ -38,7 +38,7 @@ function getConfig(input) {
"'"
);
},
list: val => {
array: val => {
if (val === '') {
return [];
}

Просмотреть файл

@ -7,9 +7,9 @@ module.exports = {
const defaultValues = {
boolean: true,
list: [],
array: [],
string: null,
json: null,
object: null,
};
function getDefault(option) {

Просмотреть файл

@ -10,7 +10,7 @@ const options = [
description:
'Configuration presets to use/extend. Note: does not work if configured in config.js',
stage: 'package',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
cli: false,
@ -20,7 +20,7 @@ const options = [
description:
'A list of presets to ignore, including nested ones inside `extends`',
stage: 'package',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
cli: false,
@ -28,7 +28,7 @@ const options = [
{
name: 'description',
description: 'Plain text description for a config or preset',
type: 'list',
type: 'array',
subType: 'string',
stage: 'repository',
allowString: true,
@ -50,7 +50,7 @@ const options = [
'Any configuration defined within this object will force override existing settings',
stage: 'package',
admin: true,
type: 'json',
type: 'object',
cli: false,
env: false,
},
@ -121,7 +121,7 @@ const options = [
name: 'onboardingConfig',
description: 'Configuration to use in onboarding PRs',
stage: 'repository',
type: 'json',
type: 'object',
default: {},
admin: true,
mergeable: true,
@ -166,7 +166,7 @@ const options = [
description:
'A configuration object containing configuration encrypted with project key.',
stage: 'repository',
type: 'json',
type: 'object',
default: null,
},
// Scheduling
@ -179,7 +179,7 @@ const options = [
{
name: 'schedule',
description: 'Times of day/week to limit branch creation to',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
cli: true,
@ -303,14 +303,14 @@ const options = [
name: 'repositories',
description: 'List of Repositories',
stage: 'global',
type: 'list',
type: 'array',
cli: false,
},
{
name: 'baseBranches',
description:
'An array of one or more custom base branches to be processed. If left empty, the default branch will be chosen',
type: 'list',
type: 'array',
stage: 'package',
cli: false,
env: false,
@ -332,13 +332,13 @@ const options = [
name: 'enabledManagers',
description:
'A list of package managers to enable. If defined, then all managers not on the list are disabled.',
type: 'list',
type: 'array',
stage: 'repository',
},
{
name: 'includePaths',
description: 'Include package files only within these defined paths',
type: 'list',
type: 'array',
subType: 'string',
stage: 'repository',
default: [],
@ -347,7 +347,7 @@ const options = [
name: 'ignorePaths',
description:
'Skip any package.json whose path matches one of these. Can be string or glob pattern',
type: 'list',
type: 'array',
subType: 'string',
stage: 'repository',
default: ['**/node_modules/**', '**/bower_components/**'],
@ -356,7 +356,7 @@ const options = [
name: 'engines',
description: 'Configuration specifically for `package.json`>`engines`',
stage: 'package',
type: 'json',
type: 'object',
default: {},
mergeable: true,
cli: false,
@ -365,7 +365,7 @@ const options = [
name: 'registryUrls',
description:
'List of URLs to try for dependency lookup. Package manager-specific',
type: 'list',
type: 'array',
subType: 'string',
default: null,
stage: 'branch',
@ -398,7 +398,7 @@ const options = [
{
name: 'ignoreDeps',
description: 'Dependencies to ignore',
type: 'list',
type: 'array',
subType: 'string',
stage: 'package',
mergeable: true,
@ -406,7 +406,7 @@ const options = [
{
name: 'packageRules',
description: 'Rules for matching package names',
type: 'list',
type: 'array',
stage: 'package',
mergeable: true,
cli: false,
@ -416,7 +416,7 @@ const options = [
name: 'languages',
description:
'List of languages to match (e.g. ["python"]). Valid only within `packageRules` object',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
parent: 'packageRules',
@ -429,7 +429,7 @@ const options = [
name: 'baseBranchList',
description:
'List of branches to match (e.g. ["master"]). Valid only within `packageRules` object',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
parent: 'packageRules',
@ -442,7 +442,7 @@ const options = [
name: 'managers',
description:
'List of package managers to match (e.g. ["pipenv"]). Valid only within `packageRules` object',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
parent: 'packageRules',
@ -455,7 +455,7 @@ const options = [
name: 'datasources',
description:
'List of datasources to match (e.g. ["orb"]). Valid only within `packageRules` object',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
parent: 'packageRules',
@ -468,7 +468,7 @@ const options = [
name: 'depTypeList',
description:
'List of depTypes to match (e.g. [`peerDependencies`]). Valid only within `packageRules` object',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
parent: 'packageRules',
@ -481,7 +481,7 @@ const options = [
name: 'packageNames',
description:
'Package names to match. Valid only within `packageRules` object',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
stage: 'package',
@ -494,7 +494,7 @@ const options = [
name: 'excludePackageNames',
description:
'Package names to exclude. Valid only within `packageRules` object',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
stage: 'package',
@ -507,7 +507,7 @@ const options = [
name: 'packagePatterns',
description:
'Package name patterns to match. Valid only within `packageRules` object.',
type: 'list',
type: 'array',
subType: 'string',
format: 'regex',
allowString: true,
@ -521,7 +521,7 @@ const options = [
name: 'excludePackagePatterns',
description:
'Package name patterns to exclude. Valid only within `packageRules` object.',
type: 'list',
type: 'array',
subType: 'string',
format: 'regex',
allowString: true,
@ -546,7 +546,7 @@ const options = [
name: 'sourceUrlPrefixes',
description:
'A list of source URL prefixes to match against, commonly used for grouping of monorepos or packages from the same organization.',
type: 'list',
type: 'array',
subType: 'string',
allowString: true,
stage: 'package',
@ -559,7 +559,8 @@ const options = [
name: 'updateTypes',
description:
'Update types to match against (major, minor, pin, etc). Valid only within `packageRules` object.',
type: 'list',
type: 'array',
// TODO: add allowedValues
subType: 'string',
allowedValues: [
'major',
@ -582,7 +583,7 @@ const options = [
name: 'paths',
description:
'List of strings or glob patterns to match against package files. Applicable inside packageRules only',
type: 'list',
type: 'array',
subType: 'string',
stage: 'repository',
parent: 'packageRules',
@ -698,7 +699,7 @@ const options = [
name: 'major',
description: 'Configuration to apply when an update type is major',
stage: 'package',
type: 'json',
type: 'object',
default: {},
cli: false,
mergeable: true,
@ -707,7 +708,7 @@ const options = [
name: 'minor',
description: 'Configuration to apply when an update type is minor',
stage: 'package',
type: 'json',
type: 'object',
default: {},
cli: false,
mergeable: true,
@ -717,7 +718,7 @@ const options = [
description:
'Configuration to apply when an update type is patch. Only applies if `separateMinorPatch` is set to true',
stage: 'package',
type: 'json',
type: 'object',
default: {},
cli: false,
mergeable: true,
@ -726,7 +727,7 @@ const options = [
name: 'pin',
description: 'Configuration to apply when an update type is pin.',
stage: 'package',
type: 'json',
type: 'object',
default: {
unpublishSafe: false,
recreateClosed: true,
@ -746,7 +747,7 @@ const options = [
description:
'Configuration to apply when updating a digest (no change in tag/version)',
stage: 'package',
type: 'json',
type: 'object',
default: {
branchTopic: '{{{depNameSanitized}}}-digest',
commitMessageExtra: 'to {{newDigestShort}}',
@ -870,7 +871,7 @@ const options = [
name: 'requiredStatusChecks',
description:
'List of status checks that must pass before automerging. Set to null to enable automerging without tests.',
type: 'list',
type: 'array',
subType: 'string',
cli: false,
env: false,
@ -986,7 +987,7 @@ const options = [
name: 'lockFileMaintenance',
description: 'Configuration for lock file maintenance',
stage: 'branch',
type: 'json',
type: 'object',
default: {
enabled: false,
recreateClosed: true,
@ -1026,7 +1027,7 @@ const options = [
{
name: 'group',
description: 'Config if groupName is enabled',
type: 'json',
type: 'object',
default: {
branchTopic: '{{{groupSlug}}}',
commitMessageTopic: '{{{groupName}}}',
@ -1039,27 +1040,27 @@ const options = [
{
name: 'labels',
description: 'Labels to add to Pull Request',
type: 'list',
type: 'array',
subType: 'string',
},
{
name: 'assignees',
description:
'Assignees for Pull Request (username in GitHub/GitLab, email address in Azure DevOps)',
type: 'list',
type: 'array',
subType: 'string',
},
{
name: 'reviewers',
description:
'Requested reviewers for Pull Requests (username in GitHub/GitLab, email or username in Azure DevOps)',
type: 'list',
type: 'array',
subType: 'string',
},
{
name: 'fileMatch',
description: 'JS RegExp pattern for matching manager files',
type: 'list',
type: 'array',
subType: 'string',
format: 'regex',
stage: 'repository',
@ -1072,7 +1073,7 @@ const options = [
name: 'js',
description: 'Configuration object for javascript language',
stage: 'package',
type: 'json',
type: 'object',
default: {},
mergeable: true,
},
@ -1080,7 +1081,7 @@ const options = [
name: 'npm',
description: 'Configuration object for npm package.json renovation',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)package.json$'],
rollbackPrs: true,
@ -1096,7 +1097,7 @@ const options = [
name: 'meteor',
description: 'Configuration object for meteor package.js renovation',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)package.js$'],
},
@ -1106,7 +1107,7 @@ const options = [
name: 'bazel',
description: 'Configuration object for bazel WORKSPACE renovation',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)WORKSPACE$'],
prBodyDefinitions: {
@ -1120,7 +1121,7 @@ const options = [
name: 'buildkite',
description: 'Configuration object for buildkite pipeline renovation',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['buildkite\\.ya?ml', '\\.buildkite/.+\\.ya?ml$'],
commitMessageTopic: 'buildkite plugin {{depName}}',
@ -1134,7 +1135,7 @@ const options = [
name: 'golang',
description: 'Configuration object for Go language',
stage: 'package',
type: 'json',
type: 'object',
default: {
commitMessageTopic: 'module {{depNameShort}}',
},
@ -1145,7 +1146,7 @@ const options = [
name: 'gomod',
description: 'Configuration object for Go modules renovation',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)go.mod$'],
},
@ -1155,7 +1156,7 @@ const options = [
name: 'postUpdateOptions',
description:
'Enable post-update options to be run after package/artifact updating',
type: 'list',
type: 'array',
default: [],
allowedValues: [
'gomodTidy',
@ -1172,7 +1173,7 @@ const options = [
releaseStatus: 'alpha',
description: 'Configuration object for ruby language',
stage: 'package',
type: 'json',
type: 'object',
default: {},
mergeable: true,
cli: false,
@ -1182,7 +1183,7 @@ const options = [
releaseStatus: 'alpha',
description: 'Configuration object for bundler Gemfiles',
stage: 'package',
type: 'json',
type: 'object',
default: {
enabled: false,
fileMatch: ['(^|/)Gemfile$'],
@ -1194,7 +1195,7 @@ const options = [
name: 'terraform',
description: 'Configuration object for Terraform module renovation',
stage: 'repository',
type: 'json',
type: 'object',
default: {
commitMessageTopic: 'Terraform module {{depNameShort}}',
fileMatch: ['\\.tf$'],
@ -1207,7 +1208,7 @@ const options = [
releaseStatus: 'unpublished',
description: 'Configuration option for Rust package management.',
stage: 'package',
type: 'json',
type: 'object',
default: {},
mergeable: true,
cli: false,
@ -1217,7 +1218,7 @@ const options = [
releaseStatus: 'unpublished',
description: 'Configuration object for Cargo crate renovation.',
stage: 'repository',
type: 'json',
type: 'object',
default: {
enabled: false,
commitMessageTopic: 'Rust crate {{depName}}',
@ -1230,7 +1231,7 @@ const options = [
name: 'supportPolicy',
description:
'Dependency support policy, e.g. used for LTS vs non-LTS etc (node-only)',
type: 'list',
type: 'array',
subType: 'string',
stage: 'package',
allowString: true,
@ -1239,7 +1240,7 @@ const options = [
name: 'node',
description: 'Configuration object for node version renovation',
stage: 'package',
type: 'json',
type: 'object',
default: {
commitMessageTopic: 'Node.js',
major: {
@ -1253,7 +1254,7 @@ const options = [
name: 'travis',
description: 'Configuration object for .travis.yml node version renovation',
stage: 'package',
type: 'json',
type: 'object',
default: {
enabled: false,
fileMatch: ['^.travis.yml$'],
@ -1266,7 +1267,7 @@ const options = [
name: 'nvm',
description: 'Configuration object for .nvmrc files',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['^.nvmrc$'],
versionScheme: 'node',
@ -1278,7 +1279,7 @@ const options = [
name: 'docker',
description: 'Configuration object for Docker language',
stage: 'package',
type: 'json',
type: 'object',
default: {
versionScheme: 'docker',
managerBranchPrefix: 'docker-',
@ -1316,7 +1317,7 @@ const options = [
description:
'Configuration object for Docker Compose renovation. Also inherits settings from `docker` object.',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)docker-compose[^/]*\\.ya?ml$'],
},
@ -1327,7 +1328,7 @@ const options = [
name: 'dockerfile',
description: 'Configuration object for Dockerfile renovation',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)Dockerfile$'],
},
@ -1339,7 +1340,7 @@ const options = [
description:
'Configuration object for Kubernetes renovation. Also inherits settings from `docker` object.',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: [],
},
@ -1351,7 +1352,7 @@ const options = [
description:
'Configuration object for CircleCI yml renovation. Also inherits settings from `docker` object.',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/).circleci/config.yml$'],
},
@ -1363,7 +1364,7 @@ const options = [
description:
'Configuration object for Ansible yaml renovation. Also inherits settings from `docker` object.',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)tasks/[^/]+\\.ya?ml$'],
},
@ -1375,7 +1376,7 @@ const options = [
description:
'Configuration object for GitHub Actions workflow renovation. Also inherits settings from `docker` object.',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['^\\.github/main.workflow$'],
pinDigests: true,
@ -1387,7 +1388,7 @@ const options = [
name: 'composer',
description: 'Configuration object for composer.json files',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)([\\w-]*)composer.json$'],
versionScheme: 'composer',
@ -1399,7 +1400,7 @@ const options = [
name: 'php',
description: 'Configuration object for php',
stage: 'package',
type: 'json',
type: 'object',
default: {},
mergeable: true,
cli: false,
@ -1408,7 +1409,7 @@ const options = [
name: 'pip_requirements',
description: 'Configuration object for requirements.txt files',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)([\\w-]*)requirements.(txt|pip)$'],
},
@ -1420,7 +1421,7 @@ const options = [
releaseStatus: 'beta',
description: 'Configuration object for setup.py files',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)setup.py$'],
},
@ -1432,7 +1433,7 @@ const options = [
releaseStatus: 'beta',
description: 'Configuration object for Pipfile files',
stage: 'package',
type: 'json',
type: 'object',
default: {
enabled: false,
fileMatch: ['(^|/)Pipfile$'],
@ -1444,7 +1445,7 @@ const options = [
name: 'python',
description: 'Configuration object for python',
stage: 'package',
type: 'json',
type: 'object',
default: {
versionScheme: 'pep440',
},
@ -1463,7 +1464,7 @@ const options = [
name: 'java',
description: 'Configuration object for all Java package managers',
stage: 'package',
type: 'json',
type: 'object',
default: {},
mergeable: true,
cli: false,
@ -1473,7 +1474,7 @@ const options = [
releaseStatus: 'beta',
description: 'Configuration object for build.gradle files',
stage: 'package',
type: 'json',
type: 'object',
default: {
enabled: false,
fileMatch: ['\\.gradle$', '(^|/)gradle.properties$'],
@ -1487,7 +1488,7 @@ const options = [
name: 'gradle-wrapper',
description: 'Configuration object for gradle-wrapper.properties files',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['(^|/)gradle/wrapper/gradle-wrapper.properties$'],
},
@ -1499,7 +1500,7 @@ const options = [
description: 'Configuration object for when renovating Maven pom.xml files',
releaseStatus: 'alpha',
stage: 'package',
type: 'json',
type: 'object',
default: {
enabled: false,
fileMatch: ['\\.pom.xml$', '(^|/)pom.xml$'],
@ -1513,7 +1514,7 @@ const options = [
description:
'Configuration object for GitLab CI yml renovation. Also inherits settings from `docker` object.',
stage: 'repository',
type: 'json',
type: 'object',
default: {
fileMatch: ['^\\.gitlab-ci\\.yml$'],
},
@ -1524,7 +1525,7 @@ const options = [
name: 'dotnet',
description: 'Configuration object for .NET language',
stage: 'package',
type: 'json',
type: 'object',
default: {},
mergeable: true,
cli: false,
@ -1533,7 +1534,7 @@ const options = [
name: 'nuget',
description: 'Configuration object for C#/Nuget',
stage: 'package',
type: 'json',
type: 'object',
default: {
fileMatch: ['\\.csproj$'],
},
@ -1543,7 +1544,7 @@ const options = [
{
name: 'hostRules',
description: 'Host rules/configuration including credentials',
type: 'list',
type: 'array',
stage: 'repository',
cli: true,
mergeable: true,
@ -1568,14 +1569,14 @@ const options = [
{
name: 'prBodyColumns',
description: 'List of columns to use in PR bodies',
type: 'list',
type: 'array',
default: ['Package', 'Type', 'Update', 'Change', 'References'],
},
{
name: 'prBodyNotes',
description:
'List of additional notes/templates to be included in the Pull Request bodies.',
type: 'list',
type: 'array',
subType: 'string',
default: [],
allowString: true,
@ -1585,7 +1586,7 @@ const options = [
name: 'suppressNotifications',
description:
'Options to suppress various types of warnings and other notifications',
type: 'list',
type: 'array',
default: [],
allowedValues: [
'prIgnoreNotification',

Просмотреть файл

@ -23,9 +23,9 @@ function getConfig(env) {
const coersions = {
boolean: val => val === 'true',
list: val => val.split(',').map(el => el.trim()),
array: val => val.split(',').map(el => el.trim()),
string: val => val.replace(/\\n/g, '\n'),
json: val => JSON.parse(val),
object: val => JSON.parse(val),
integer: parseInt,
};

Просмотреть файл

@ -151,7 +151,7 @@ function mergeChildConfig(parent, child) {
parentConfig[option.name]
) {
logger.trace(`mergeable option: ${option.name}`);
if (option.type === 'list') {
if (option.type === 'array') {
config[option.name] = (parentConfig[option.name] || []).concat(
config[option.name] || []
);

Просмотреть файл

@ -345,7 +345,7 @@ function migrateConfig(config) {
});
isMigrated = true;
delete migratedConfig.depTypes;
} else if (optionTypes[key] === 'json' && is.boolean(val)) {
} else if (optionTypes[key] === 'object' && is.boolean(val)) {
isMigrated = true;
migratedConfig[key] = { enabled: val };
} else if (optionTypes[key] === 'boolean') {

Просмотреть файл

@ -123,7 +123,7 @@ async function validateConfig(config, isPreset, parentPath) {
)} (${typeof val})`,
});
}
} else if (type === 'list' && val) {
} else if (type === 'array' && val) {
if (!is.array(val)) {
errors.push({
depName: 'Configuration Error',
@ -257,7 +257,7 @@ async function validateConfig(config, isPreset, parentPath) {
message: `Configuration option \`${currentPath}\` should be a string`,
});
}
} else if (type === 'json') {
} else if (type === 'object') {
if (is.object(val)) {
const subValidation = await module.exports.validateConfig(
val,