From 4ec85ad81827b64ca54a5f2c84bda2ccc71a7eb0 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@keylocation.sg> Date: Sun, 24 Dec 2017 11:14:34 +0100 Subject: [PATCH] feat: use version in pr title for synchronised groups (#1333) Now, if every upgrade in a group has the same new version, then the PR title will include this version. Closes #1332 --- docs/configuration.md | 3 +- lib/config/definitions.js | 1 - lib/config/templates/group/pr-title.hbs | 2 +- lib/workers/repository/updates/generate.js | 9 +++++ .../__snapshots__/resolve.spec.js.snap | 21 ++++------ .../package/__snapshots__/index.spec.js.snap | 1 - .../__snapshots__/branchify.spec.js.snap | 37 +++++++++++++----- .../repository/updates/generate.spec.js | 38 ++++++++++++++++++- 8 files changed, 82 insertions(+), 30 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 50799574ce..367176031e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -707,10 +707,9 @@ location with this method. <td>Config if groupName is enabled</td> <td>json</td> <td><pre>{ - "recreateClosed": true, "branchName": "{{branchPrefix}}{{groupSlug}}", - "prTitle": "Renovate {{groupName}} packages", "commitMessage": "Update {{groupName}} packages", + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", "prBody": "This Pull Request renovates the package group \"{{groupName}}\".\n\n{{#if schedule}}\n**Note**: This PR was created on a configured schedule (\"{{schedule}}\"{{#if timezone}} in timezone `{{timezone}}`{{/if}}) and will not receive updates outside those times.\n{{/if}}\n\n{{#each upgrades as |upgrade|}}\n- {{#if repositoryUrl}}[{{upgrade.depName}}]({{upgrade.repositoryUrl}}){{else}}{{depName}}{{/if}}: 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\n{{#if hasErrors}}\n\n---\n\n### Errors\n\nRenovate encountered some errors when processing your repository, so you are being notified here even if they do not directly apply to this PR.\n\n{{#each errors as |error|}}\n- `{{error.depName}}`: {{error.message}}\n{{/each}}\n{{/if}}\n\n{{#if hasWarnings}}\n\n---\n\n### Warnings\n\nPlease make sure the following warnings are safe to ignore:\n\n{{#each warnings as |warning|}}\n- `{{warning.depName}}`: {{warning.message}}\n{{/each}}\n{{/if}}\n\n---\n\nThis PR has been generated by [Renovate Bot](https://renovateapp.com)." }</pre></td> <td></td> diff --git a/lib/config/definitions.js b/lib/config/definitions.js index ecd73e3a5d..8ed29d400c 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -596,7 +596,6 @@ const options = [ description: 'Config if groupName is enabled', type: 'json', default: { - recreateClosed: true, branchName: template('branchName', 'group'), commitMessage: template('commitMessage', 'group'), prTitle: template('prTitle', 'group'), diff --git a/lib/config/templates/group/pr-title.hbs b/lib/config/templates/group/pr-title.hbs index c30dd38dcc..9f8028e529 100644 --- a/lib/config/templates/group/pr-title.hbs +++ b/lib/config/templates/group/pr-title.hbs @@ -1 +1 @@ -Update {{groupName}} packages +Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}} diff --git a/lib/workers/repository/updates/generate.js b/lib/workers/repository/updates/generate.js index 2bba5590dd..8c405e3c30 100644 --- a/lib/workers/repository/updates/generate.js +++ b/lib/workers/repository/updates/generate.js @@ -8,10 +8,14 @@ function generateBranchConfig(branchUpgrades) { logger.debug(`hasGroupName: ${hasGroupName}`); // Use group settings only if multiple upgrades or lazy grouping is disabled const depNames = []; + const newVersions = []; branchUpgrades.forEach(upg => { if (!depNames.includes(upg.depName)) { depNames.push(upg.depName); } + if (!newVersions.includes(upg.newVersion)) { + newVersions.push(upg.newVersion); + } }); const groupEligible = depNames.length > 1 || branchUpgrades[0].lazyGrouping === false; @@ -29,6 +33,11 @@ function generateBranchConfig(branchUpgrades) { // Delete group config regardless of whether it was applied delete upgrade.group; delete upgrade.lazyGrouping; + if (newVersions.length === 1) { + [upgrade.singleVersion] = newVersions; + } else { + upgrade.recreateClosed = true; + } // Use templates to generate strings logger.debug( { branchName: upgrade.branchName, prTitle: upgrade.prTitle }, diff --git a/test/manager/__snapshots__/resolve.spec.js.snap b/test/manager/__snapshots__/resolve.spec.js.snap index afcdc1fbd9..2a23352d6f 100644 --- a/test/manager/__snapshots__/resolve.spec.js.snap +++ b/test/manager/__snapshots__/resolve.spec.js.snap @@ -307,8 +307,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, @@ -833,8 +832,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, @@ -1369,8 +1367,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, @@ -2163,8 +2160,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, @@ -2696,8 +2692,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, @@ -3220,8 +3215,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, @@ -3753,8 +3747,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, diff --git a/test/workers/package/__snapshots__/index.spec.js.snap b/test/workers/package/__snapshots__/index.spec.js.snap index 8008d81210..00358f8739 100644 --- a/test/workers/package/__snapshots__/index.spec.js.snap +++ b/test/workers/package/__snapshots__/index.spec.js.snap @@ -78,7 +78,6 @@ Please make sure the following warnings are safe to ignore: This PR has been generated by [Renovate Bot](https://renovateapp.com).", "prTitle": "{{groupName}}", - "recreateClosed": true, }, "groupName": "Pin Dependencies", "groupSlug": null, diff --git a/test/workers/repository/updates/__snapshots__/branchify.spec.js.snap b/test/workers/repository/updates/__snapshots__/branchify.spec.js.snap index 7e00c0deb1..1f754fb6f3 100644 --- a/test/workers/repository/updates/__snapshots__/branchify.spec.js.snap +++ b/test/workers/repository/updates/__snapshots__/branchify.spec.js.snap @@ -18,11 +18,13 @@ Object { "branchName": "foo-1.1.0", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "upgrades": Array [ Object { "branchName": "foo-1.1.0", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "version": "1.1.0", }, ], @@ -32,11 +34,13 @@ Object { "branchName": "foo-2.0.0", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "upgrades": Array [ Object { "branchName": "foo-2.0.0", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "version": "2.0.0", }, ], @@ -46,11 +50,13 @@ Object { "branchName": "bar-1.1.0", "depName": "bar", "prTitle": "some-title", + "singleVersion": undefined, "upgrades": Array [ Object { "branchName": "bar-1.1.0", "depName": "bar", "prTitle": "some-title", + "singleVersion": undefined, "version": "1.1.0", }, ], @@ -347,8 +353,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, @@ -587,17 +592,20 @@ Object { "branchName": "foo", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "upgrades": Array [ Object { "branchName": "foo", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "version": "2.0.0", }, Object { "branchName": "foo", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "version": "1.1.0", }, ], @@ -607,11 +615,13 @@ Object { "branchName": "bar-1.1.0", "depName": "bar", "prTitle": "some-title", + "singleVersion": undefined, "upgrades": Array [ Object { "branchName": "bar-1.1.0", "depName": "bar", "prTitle": "some-title", + "singleVersion": undefined, "version": "1.1.0", }, ], @@ -908,8 +918,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, @@ -1150,6 +1159,7 @@ Object { "groupName": "My Group", "groupSlug": "my-group", "prTitle": "some-title", + "singleVersion": undefined, "upgrades": Array [ Object { "branchName": "renovate/my-group", @@ -1157,6 +1167,7 @@ Object { "groupName": "My Group", "groupSlug": "my-group", "prTitle": "some-title", + "singleVersion": undefined, "version": "1.1.0", }, Object { @@ -1165,6 +1176,7 @@ Object { "groupName": "My Group", "groupSlug": "my-group", "prTitle": "some-title", + "singleVersion": undefined, "version": "1.1.0", }, ], @@ -1174,11 +1186,13 @@ Object { "branchName": "foo", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "upgrades": Array [ Object { "branchName": "foo", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "version": "2.0.0", }, ], @@ -1475,8 +1489,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, @@ -1714,10 +1727,12 @@ Object { Object { "branchName": "foo-1.1.0", "prTitle": "some-title", + "singleVersion": undefined, "upgrades": Array [ Object { "branchName": "foo-1.1.0", "prTitle": "some-title", + "singleVersion": undefined, "version": "1.1.0", }, ], @@ -1726,10 +1741,12 @@ Object { Object { "branchName": "bar-1.1.0", "prTitle": "some-title", + "singleVersion": undefined, "upgrades": Array [ Object { "branchName": "bar-1.1.0", "prTitle": "some-title", + "singleVersion": undefined, "version": "1.1.0", }, ], @@ -2030,8 +2047,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, @@ -2279,11 +2295,13 @@ Object { "branchName": "foo-1.1.0", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "upgrades": Array [ Object { "branchName": "foo-1.1.0", "depName": "foo", "prTitle": "some-title", + "singleVersion": undefined, "version": "1.1.0", }, ], @@ -2580,8 +2598,7 @@ Please make sure the following warnings are safe to ignore: --- This PR has been generated by [Renovate Bot](https://renovateapp.com).", - "prTitle": "Update {{groupName}} packages", - "recreateClosed": true, + "prTitle": "Update {{groupName}} packages{{#if singleVersion}} to {{#unless isRange}}v{{/unless}}{{singleVersion}}{{/if}}", }, "groupName": null, "groupSlug": null, diff --git a/test/workers/repository/updates/generate.spec.js b/test/workers/repository/updates/generate.spec.js index 99ad7f0544..fce6db8d03 100644 --- a/test/workers/repository/updates/generate.spec.js +++ b/test/workers/repository/updates/generate.spec.js @@ -73,7 +73,7 @@ describe('workers/repository/updates/generate', () => { expect(res.foo).toBe(1); expect(res.groupName).toBeUndefined(); }); - it('groups multiple upgrades', () => { + it('groups multiple upgrades same version', () => { const branch = [ { depName: 'some-dep', @@ -82,6 +82,7 @@ describe('workers/repository/updates/generate', () => { prTitle: 'some-title', lazyGrouping: true, foo: 1, + newVersion: '5.1.2', group: { foo: 2, }, @@ -93,6 +94,7 @@ describe('workers/repository/updates/generate', () => { prTitle: 'some-title', lazyGrouping: true, foo: 1, + newVersion: '5.1.2', group: { foo: 2, }, @@ -100,6 +102,40 @@ describe('workers/repository/updates/generate', () => { ]; const res = generateBranchConfig(branch); expect(res.foo).toBe(2); + expect(res.singleVersion).toBeDefined(); + expect(res.groupName).toBeDefined(); + }); + it('groups multiple upgrades different version', () => { + const branch = [ + { + depName: 'some-dep', + groupName: 'some-group', + branchName: 'some-branch', + prTitle: 'some-title', + lazyGrouping: true, + foo: 1, + newVersion: '5.1.2', + group: { + foo: 2, + }, + }, + { + depName: 'some-other-dep', + groupName: 'some-group', + branchName: 'some-branch', + prTitle: 'some-title', + lazyGrouping: true, + foo: 1, + newVersion: '1.1.0', + group: { + foo: 2, + }, + }, + ]; + const res = generateBranchConfig(branch); + expect(res.foo).toBe(2); + expect(res.singleVersion).toBeUndefined(); + expect(res.recreateClosed).toBe(true); expect(res.groupName).toBeDefined(); }); it('uses semantic commits', () => { -- GitLab