refactor: change group config structure

This changes how group are configured to align with the new lock file configuration.

BREAKING CHANGE: old group* template options are no longer supported but can be migrated into group object
This commit is contained in:
Rhys Arkins 2017-07-01 06:48:38 +02:00
parent 6f49927a45
commit 3d9cd11611
13 changed files with 35 additions and 46 deletions

View file

@ -187,10 +187,12 @@ Obviously, you can't set repository or package file location with this method.
| `lazyGrouping` | Use group names only when multiple dependencies upgraded | boolean | `true` | `RENOVATE_LAZY_GROUPING` | `--lazy-grouping` | | `lazyGrouping` | Use group names only when multiple dependencies upgraded | boolean | `true` | `RENOVATE_LAZY_GROUPING` | `--lazy-grouping` |
| `groupName` | Human understandable name for the dependency group | string | `null` | `RENOVATE_GROUP_NAME` | `--group-name` | | `groupName` | Human understandable name for the dependency group | string | `null` | `RENOVATE_GROUP_NAME` | `--group-name` |
| `groupSlug` | Slug to use for group (e.g. in branch name). Will be calculated from groupName if null | string | `null` | `RENOVATE_GROUP_SLUG` | `--group-slug` | | `groupSlug` | Slug to use for group (e.g. in branch name). Will be calculated from groupName if null | string | `null` | `RENOVATE_GROUP_SLUG` | `--group-slug` |
| `groupBranchName` | Branch name template for the group | string | `"renovate/{{groupSlug}}"` | `RENOVATE_GROUP_BRANCH_NAME` | | | `group` | Config if groupName is enabled | json | `{
| `groupCommitMessage` | Group commit message | string | `"{{semanticPrefix}}Renovate {{groupName}} packages"` | `RENOVATE_GROUP_COMMIT_MESSAGE` | | "branchName": "renovate/{{groupSlug}}",
| `groupPrTitle` | Pull Request title template for the group | string | `"{{semanticPrefix}}Renovate {{groupName}} packages"` | `RENOVATE_GROUP_PR_TITLE` | | "commitMessage": "{{semanticPrefix}}Renovate {{groupName}} packages",
| `groupPrBody` | Pull Request body template for the group | string | `"This {{#if isGitHub}}Pull{{else}}Merge{{/if}} Request renovates the package group \"{{groupName}}\".\n\n{{#each upgrades as |upgrade|}}\n- [{{upgrade.depName}}]({{upgrade.repositoryUrl}}): from `{{upgrade.currentVersion}}` to `{{upgrade.newVersion}}`\n{{/each}}\n\n{{#unless isPin}}\n### Commits\n\n{{#each upgrades as |upgrade|}}\n{{#if upgrade.releases.length}}\n<details>\n<summary>{{upgrade.githubName}}</summary>\n{{#each upgrade.releases as |release|}}\n\n#### {{release.version}}\n{{#each release.commits as |commit|}}\n- [`{{commit.shortSha}}`]({{commit.url}}){{commit.message}}\n{{/each}}\n{{/each}}\n\n</details>\n{{/if}}\n{{/each}}\n{{/unless}}\n<br />\n\nThis {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](https://keylocation.sg/our-tech/renovate)."` | `RENOVATE_GROUP_PR_BODY` | | "prTitle": "{{semanticPrefix}}Renovate {{groupName}} packages",
"prBody": "This {{#if isGitHub}}Pull{{else}}Merge{{/if}} Request renovates the package group \"{{groupName}}\".\n\n{{#each upgrades as |upgrade|}}\n- [{{upgrade.depName}}]({{upgrade.repositoryUrl}}): from `{{upgrade.currentVersion}}` to `{{upgrade.newVersion}}`\n{{/each}}\n\n{{#unless isPin}}\n### Commits\n\n{{#each upgrades as |upgrade|}}\n{{#if upgrade.releases.length}}\n<details>\n<summary>{{upgrade.githubName}}</summary>\n{{#each upgrade.releases as |release|}}\n\n#### {{release.version}}\n{{#each release.commits as |commit|}}\n- [`{{commit.shortSha}}`]({{commit.url}}){{commit.message}}\n{{/each}}\n{{/each}}\n\n</details>\n{{/if}}\n{{/each}}\n{{/unless}}\n<br />\n\nThis {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](https://keylocation.sg/our-tech/renovate)."
}` | `RENOVATE_GROUP` | |
| `labels` | Labels to add to Pull Request | list | `[]` | `RENOVATE_LABELS` | `--labels` | | `labels` | Labels to add to Pull Request | list | `[]` | `RENOVATE_LABELS` | `--labels` |
| `assignees` | Assignees for Pull Request | list | `[]` | `RENOVATE_ASSIGNEES` | `--assignees` | | `assignees` | Assignees for Pull Request | list | `[]` | `RENOVATE_ASSIGNEES` | `--assignees` |
| `reviewers` | Requested reviewers for Pull Requests (GitHub only) | list | `[]` | `RENOVATE_REVIEWERS` | `--reviewers` | | `reviewers` | Requested reviewers for Pull Requests (GitHub only) | list | `[]` | `RENOVATE_REVIEWERS` | `--reviewers` |

View file

@ -1,11 +1,11 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
function template(name) { function template(name, subdir = 'default/') {
const shortName = `${name.replace(/([A-Z])/g, '-$1').toLowerCase()}.hbs`; const shortName = `${name.replace(/([A-Z])/g, '-$1').toLowerCase()}.hbs`;
const hbsContents = fs.readFileSync( const hbsContents = fs.readFileSync(
// Long path is so that it works whether code is run from lib or dist // Long path is so that it works whether code is run from lib or dist
path.resolve(__dirname, '../../lib/config/templates/', shortName), path.resolve(__dirname, '../../lib/config/templates/', subdir, shortName),
'utf8' 'utf8'
); );
// Strip off any trailing line break // Strip off any trailing line break
@ -215,7 +215,7 @@ const options = [
default: 'pr', default: 'pr',
onboarding: false, onboarding: false,
}, },
// String templates // Default templates
{ {
name: 'branchName', name: 'branchName',
description: 'Branch name template', description: 'Branch name template',
@ -297,36 +297,19 @@ const options = [
onboarding: false, onboarding: false,
}, },
{ {
name: 'groupBranchName', name: 'group',
description: 'Branch name template for the group', description: 'Config if groupName is enabled',
type: 'string', type: 'json',
default: template('groupBranchName'), default: {
cli: false, branchName: template('branchName', 'group'),
onboarding: false, commitMessage: template('commitMessage', 'group'),
}, prTitle: template('prTitle', 'group'),
{ prBody: template('prBody', 'group'),
name: 'groupCommitMessage', },
description: 'Group commit message',
type: 'string',
default: template('groupCommitMessage'),
cli: false,
onboarding: false,
},
{
name: 'groupPrTitle',
description: 'Pull Request title template for the group',
type: 'string',
default: template('groupPrTitle'),
cli: false,
onboarding: false,
},
{
name: 'groupPrBody',
description: 'Pull Request body template for the group',
type: 'string',
default: template('groupPrBody'),
cli: false, cli: false,
env: false,
onboarding: false, onboarding: false,
mergeable: true,
}, },
// Pull Request options // Pull Request options
{ {

View file

@ -36,18 +36,18 @@ async function groupUpgradesByBranch(upgrades, logger) {
// Check whether to use a group name // Check whether to use a group name
let branchName; let branchName;
if (upgrade.groupName) { if (upgrade.groupName) {
upgrade.groupSlug =
upgrade.groupSlug ||
upgrade.groupName.toLowerCase().replace(/[^a-z0-9+]+/g, '-');
branchName = handlebars.compile(upgrade.groupBranchName)(upgrade);
logger.debug( logger.debug(
{ branchName }, { branchName },
`Dependency ${upgrade.depName} is part of group '${upgrade.groupName}'` `Dependency ${upgrade.depName} is part of group '${upgrade.groupName}'`
); );
upgrade.groupSlug =
upgrade.groupSlug ||
upgrade.groupName.toLowerCase().replace(/[^a-z0-9+]+/g, '-');
branchName = handlebars.compile(upgrade.group.branchName)(upgrade);
if (branchUpgrades[branchName]) { if (branchUpgrades[branchName]) {
upgrade.commitMessage = upgrade.groupCommitMessage; upgrade.commitMessage = upgrade.group.commitMessage;
upgrade.prTitle = upgrade.groupPrTitle; upgrade.prTitle = upgrade.group.prTitle;
upgrade.prBody = upgrade.groupPrBody; upgrade.prBody = upgrade.group.prBody;
} }
} else { } else {
branchName = handlebars.compile(upgrade.branchName)(upgrade); branchName = handlebars.compile(upgrade.branchName)(upgrade);

View file

@ -56,7 +56,9 @@ Object {
Object { Object {
"branchName": "bar-{{version}}", "branchName": "bar-{{version}}",
"commitMessage": undefined, "commitMessage": undefined,
"groupBranchName": "renovate/my-group", "group": Object {
"branchName": "renovate/my-group",
},
"groupName": "My Group", "groupName": "My Group",
"groupSlug": "my-group", "groupSlug": "my-group",
"prBody": undefined, "prBody": undefined,
@ -65,7 +67,9 @@ Object {
}, },
Object { Object {
"branchName": "foo", "branchName": "foo",
"groupBranchName": "renovate/{{groupSlug}}", "group": Object {
"branchName": "renovate/{{groupSlug}}",
},
"groupName": "My Group", "groupName": "My Group",
"groupSlug": "my-group", "groupSlug": "my-group",
"version": "1.1.0", "version": "1.1.0",

View file

@ -104,7 +104,7 @@ describe('workers/repository/upgrades', () => {
branchName: 'foo', branchName: 'foo',
version: '1.1.0', version: '1.1.0',
groupName: 'My Group', groupName: 'My Group',
groupBranchName: 'renovate/{{groupSlug}}', group: { branchName: 'renovate/{{groupSlug}}' },
}, },
{ {
branchName: 'foo', branchName: 'foo',
@ -114,7 +114,7 @@ describe('workers/repository/upgrades', () => {
branchName: 'bar-{{version}}', branchName: 'bar-{{version}}',
version: '1.1.0', version: '1.1.0',
groupName: 'My Group', groupName: 'My Group',
groupBranchName: 'renovate/my-group', group: { branchName: 'renovate/my-group' },
}, },
]; ];
const res = await upgrades.groupUpgradesByBranch(input, logger); const res = await upgrades.groupUpgradesByBranch(input, logger);