Skip to content

Commit

Permalink
fix: expose more fields to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 3, 2021
1 parent 29700db commit 1914a2e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 54 deletions.
91 changes: 46 additions & 45 deletions lib/config/__snapshots__/migration.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,51 @@ Object {
}
`;

exports[`config/migration migrateConfig(config, parentConfig) it migrates packageRules 1`] = `
Object {
"packageRules": Array [
Object {
"excludePackageNames": Array [
"baz",
],
"excludePackagePatterns": Array [
"^baz",
],
"matchBaseBranches": Array [
"master",
],
"matchDatasources": Array [
"orb",
],
"matchDepTypes": Array [
"peerDependencies",
],
"matchLanguages": Array [
"python",
],
"matchManagers": Array [
"dockerfile",
],
"matchPackageNames": Array [
"foo",
],
"matchPackagePatterns": Array [
"^bar",
],
"matchPaths": Array [
"package.json",
],
"matchSourceUrlPrefixes": Array [
"https://github.com/vuejs/vue",
],
"matchUpdateTypes": Array [
"major",
],
},
],
}
`;

exports[`config/migration migrateConfig(config, parentConfig) migrates before and after schedules 1`] = `
Object {
"major": Object {
Expand Down Expand Up @@ -39,6 +84,7 @@ Object {
"baseBranches": Array [
"next",
],
"branchName": "{{{branchPrefix}}}{{{additionalBranchPrefix}}}{{{branchTopic}}}",
"branchPrefix": "renovate/",
"commitMessage": "{{#if semanticCommitType}}{{semanticCommitType}}{{#if semanticCommitScope}}({{semanticCommitScope}}){{/if}}: {{/if}}some commit message",
"commitMessageExtra": "{{currentValue}} something",
Expand Down Expand Up @@ -276,51 +322,6 @@ Object {
}
`;

exports[`config/migration migrateConfig(config, parentConfig) it migrates packageRules 1`] = `
Object {
"packageRules": Array [
Object {
"excludePackageNames": Array [
"baz",
],
"excludePackagePatterns": Array [
"^baz",
],
"matchBaseBranches": Array [
"master",
],
"matchDatasources": Array [
"orb",
],
"matchDepTypes": Array [
"peerDependencies",
],
"matchLanguages": Array [
"python",
],
"matchManagers": Array [
"dockerfile",
],
"matchPackageNames": Array [
"foo",
],
"matchPackagePatterns": Array [
"^bar",
],
"matchPaths": Array [
"package.json",
],
"matchSourceUrlPrefixes": Array [
"https://github.com/vuejs/vue",
],
"matchUpdateTypes": Array [
"major",
],
},
],
}
`;

exports[`config/migration migrateConfig(config, parentConfig) migrates packages 1`] = `
Object {
"packageRules": Array [
Expand Down
2 changes: 2 additions & 0 deletions lib/config/migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ describe('config/migration', () => {
gomodTidy: true,
upgradeInRange: true,
automergeType: 'branch-push',
branchName:
'{{{branchPrefix}}}{{{managerBranchPrefix}}}{{{branchTopic}}}',
baseBranch: 'next',
managerBranchPrefix: 'foo',
branchPrefix: 'renovate/{{parentDir}}-',
Expand Down
13 changes: 12 additions & 1 deletion lib/config/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ export function migrateConfig(
} else if (val === false) {
migratedConfig.trustLevel = 'low';
}
} else if (
key === 'branchName' &&
is.string(val) &&
val?.includes('{{managerBranchPrefix}}')
) {
migratedConfig.branchName = val.replace(
'{{managerBranchPrefix}}',
'{{additionalBranchPrefix}}'
);
} else if (key === 'managerBranchPrefix') {
delete migratedConfig.managerBranchPrefix;
migratedConfig.additionalBranchPrefix = val;
Expand Down Expand Up @@ -491,7 +500,9 @@ export function migrateConfig(
.replace(/currentVersion/g, 'currentValue')
.replace(/newVersion/g, 'newValue')
.replace(/newValueMajor/g, 'newMajor')
.replace(/newValueMinor/g, 'newMinor');
.replace(/newValueMinor/g, 'newMinor')
.replace(/newVersionMajor/g, 'newMajor')
.replace(/newVersionMinor/g, 'newMinor');
} else if (key === 'raiseDeprecationWarnings') {
delete migratedConfig.raiseDeprecationWarnings;
if (val === false) {
Expand Down
20 changes: 12 additions & 8 deletions lib/util/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export const allowedFields = {
releases: 'An array of releases for an upgrade',
releaseNotes: 'A ChangeLogNotes object for the release',
repository: 'The current repository',
semanticPrefix: 'The fully generated semantic prefix for commit messages',
sourceUrl: 'The source URL for the package',
toVersion: 'The new version in the upgrade, e.g. "3.1.0"',
updateType: 'One of digest, pin, rollback, patch, minor, major',
upgrades: 'An array of upgrade objects in the branch',
Expand Down Expand Up @@ -144,14 +146,16 @@ export function compile(
): string {
const filteredInput = filterFields ? getFilteredObject(input) : input;
logger.trace({ template, filteredInput }, 'Compiling template');
const matches = template.matchAll(templateRegex);
for (const match of matches) {
const varName = match[3];
if (!allowedFieldsList.includes(varName)) {
logger.info(
{ varName, template },
'Disallowed variable name in template'
);
if (filterFields) {
const matches = template.matchAll(templateRegex);
for (const match of matches) {
const varName = match[3];
if (!allowedFieldsList.includes(varName)) {
logger.info(
{ varName, template },
'Disallowed variable name in template'
);
}
}
}
return handlebars.compile(template)(filteredInput);
Expand Down

0 comments on commit 1914a2e

Please sign in to comment.