diff --git a/docs/configuration.md b/docs/configuration.md index 9622839ea50384b7289e70a9aef2b501e13d076c..f5bd594abfe4b37b3dbde3d4ec10b06b6bec8eb7 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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` | | `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` | -| `groupBranchName` | Branch name template for the group | string | `"renovate/{{groupSlug}}"` | `RENOVATE_GROUP_BRANCH_NAME` | | -| `groupCommitMessage` | Group commit message | string | `"{{semanticPrefix}}Renovate {{groupName}} packages"` | `RENOVATE_GROUP_COMMIT_MESSAGE` | | -| `groupPrTitle` | Pull Request title template for the group | string | `"{{semanticPrefix}}Renovate {{groupName}} packages"` | `RENOVATE_GROUP_PR_TITLE` | | -| `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` | | +| `group` | Config if groupName is enabled | json | `{ + "branchName": "renovate/{{groupSlug}}", + "commitMessage": "{{semanticPrefix}}Renovate {{groupName}} packages", + "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` | | `assignees` | Assignees for Pull Request | list | `[]` | `RENOVATE_ASSIGNEES` | `--assignees` | | `reviewers` | Requested reviewers for Pull Requests (GitHub only) | list | `[]` | `RENOVATE_REVIEWERS` | `--reviewers` | diff --git a/lib/config/definitions.js b/lib/config/definitions.js index b7f676e8dfd779935951f83c62329eb0aca0d3c2..92a17ca2d1c91bb06f57b121a42765263b7453d0 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -1,11 +1,11 @@ const fs = require('fs'); const path = require('path'); -function template(name) { +function template(name, subdir = 'default/') { const shortName = `${name.replace(/([A-Z])/g, '-$1').toLowerCase()}.hbs`; const hbsContents = fs.readFileSync( // 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' ); // Strip off any trailing line break @@ -215,7 +215,7 @@ const options = [ default: 'pr', onboarding: false, }, - // String templates + // Default templates { name: 'branchName', description: 'Branch name template', @@ -297,36 +297,19 @@ const options = [ onboarding: false, }, { - name: 'groupBranchName', - description: 'Branch name template for the group', - type: 'string', - default: template('groupBranchName'), - cli: false, - onboarding: false, - }, - { - 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'), + name: 'group', + description: 'Config if groupName is enabled', + type: 'json', + default: { + branchName: template('branchName', 'group'), + commitMessage: template('commitMessage', 'group'), + prTitle: template('prTitle', 'group'), + prBody: template('prBody', 'group'), + }, cli: false, + env: false, onboarding: false, + mergeable: true, }, // Pull Request options { diff --git a/lib/config/templates/branch-name.hbs b/lib/config/templates/default/branch-name.hbs similarity index 100% rename from lib/config/templates/branch-name.hbs rename to lib/config/templates/default/branch-name.hbs diff --git a/lib/config/templates/commit-message.hbs b/lib/config/templates/default/commit-message.hbs similarity index 100% rename from lib/config/templates/commit-message.hbs rename to lib/config/templates/default/commit-message.hbs diff --git a/lib/config/templates/pr-body.hbs b/lib/config/templates/default/pr-body.hbs similarity index 100% rename from lib/config/templates/pr-body.hbs rename to lib/config/templates/default/pr-body.hbs diff --git a/lib/config/templates/pr-title.hbs b/lib/config/templates/default/pr-title.hbs similarity index 100% rename from lib/config/templates/pr-title.hbs rename to lib/config/templates/default/pr-title.hbs diff --git a/lib/config/templates/group-branch-name.hbs b/lib/config/templates/group/branch-name.hbs similarity index 100% rename from lib/config/templates/group-branch-name.hbs rename to lib/config/templates/group/branch-name.hbs diff --git a/lib/config/templates/group-commit-message.hbs b/lib/config/templates/group/commit-message.hbs similarity index 100% rename from lib/config/templates/group-commit-message.hbs rename to lib/config/templates/group/commit-message.hbs diff --git a/lib/config/templates/group-pr-body.hbs b/lib/config/templates/group/pr-body.hbs similarity index 100% rename from lib/config/templates/group-pr-body.hbs rename to lib/config/templates/group/pr-body.hbs diff --git a/lib/config/templates/group-pr-title.hbs b/lib/config/templates/group/pr-title.hbs similarity index 100% rename from lib/config/templates/group-pr-title.hbs rename to lib/config/templates/group/pr-title.hbs diff --git a/lib/workers/repository/upgrades.js b/lib/workers/repository/upgrades.js index 74c4474585c16feb99bec21e10a766fff9f631f1..0833b51557fcabc51e35734e3f409475552cb8bc 100644 --- a/lib/workers/repository/upgrades.js +++ b/lib/workers/repository/upgrades.js @@ -36,18 +36,18 @@ async function groupUpgradesByBranch(upgrades, logger) { // Check whether to use a group name let branchName; if (upgrade.groupName) { - upgrade.groupSlug = - upgrade.groupSlug || - upgrade.groupName.toLowerCase().replace(/[^a-z0-9+]+/g, '-'); - branchName = handlebars.compile(upgrade.groupBranchName)(upgrade); logger.debug( { branchName }, `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]) { - upgrade.commitMessage = upgrade.groupCommitMessage; - upgrade.prTitle = upgrade.groupPrTitle; - upgrade.prBody = upgrade.groupPrBody; + upgrade.commitMessage = upgrade.group.commitMessage; + upgrade.prTitle = upgrade.group.prTitle; + upgrade.prBody = upgrade.group.prBody; } } else { branchName = handlebars.compile(upgrade.branchName)(upgrade); diff --git a/test/workers/repository/__snapshots__/upgrades.spec.js.snap b/test/workers/repository/__snapshots__/upgrades.spec.js.snap index 06103cebda13e58885229f3033f8604860cb6f3d..d0827b81200be8e2fe96857a07a666a61e0d66fa 100644 --- a/test/workers/repository/__snapshots__/upgrades.spec.js.snap +++ b/test/workers/repository/__snapshots__/upgrades.spec.js.snap @@ -56,7 +56,9 @@ Object { Object { "branchName": "bar-{{version}}", "commitMessage": undefined, - "groupBranchName": "renovate/my-group", + "group": Object { + "branchName": "renovate/my-group", + }, "groupName": "My Group", "groupSlug": "my-group", "prBody": undefined, @@ -65,7 +67,9 @@ Object { }, Object { "branchName": "foo", - "groupBranchName": "renovate/{{groupSlug}}", + "group": Object { + "branchName": "renovate/{{groupSlug}}", + }, "groupName": "My Group", "groupSlug": "my-group", "version": "1.1.0", diff --git a/test/workers/repository/upgrades.spec.js b/test/workers/repository/upgrades.spec.js index c2daf9ffc7690d9cf1349c12f73ca776b6b78e22..6cda160f3d011650d76479860d865502d163e5fa 100644 --- a/test/workers/repository/upgrades.spec.js +++ b/test/workers/repository/upgrades.spec.js @@ -104,7 +104,7 @@ describe('workers/repository/upgrades', () => { branchName: 'foo', version: '1.1.0', groupName: 'My Group', - groupBranchName: 'renovate/{{groupSlug}}', + group: { branchName: 'renovate/{{groupSlug}}' }, }, { branchName: 'foo', @@ -114,7 +114,7 @@ describe('workers/repository/upgrades', () => { branchName: 'bar-{{version}}', version: '1.1.0', groupName: 'My Group', - groupBranchName: 'renovate/my-group', + group: { branchName: 'renovate/my-group' }, }, ]; const res = await upgrades.groupUpgradesByBranch(input, logger);