diff --git a/lib/config/definitions.js b/lib/config/definitions.js index 886a527d6a15b10105f4a8d97d2546732a1d3404..e9e263a3dae0c77b59a1b963a84b57b0a9a2dfbd 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -1180,6 +1180,15 @@ const options = [ type: 'list', default: ['Package', 'Type', 'Update', 'New value', 'References'], }, + { + name: 'prBodyNotes', + description: + 'List of additional notes/templates to be included in the Pull Request bodies.', + type: 'list', + default: [], + allowString: true, + mergeable: true, + }, ]; function getOptions() { diff --git a/lib/workers/pr/pr-body.js b/lib/workers/pr/pr-body.js index e3995190f7d567afc9c19d259017f885f75f0ede..cdb7195daf565b0e8ceb6bb8b6714f42f8944a38 100644 --- a/lib/workers/pr/pr-body.js +++ b/lib/workers/pr/pr-body.js @@ -1,3 +1,4 @@ +const is = require('@sindresorhus/is'); const handlebars = require('handlebars'); const releaseNotesHbs = require('./changelog/hbs-template'); @@ -98,6 +99,27 @@ async function getPrBody(config) { prBody += uniqueRows.join(''); prBody += '\n\n'; + const notes = []; + for (const upgrade of config.upgrades) { + if (!is.empty(upgrade.prBodyNotes)) { + for (const note of upgrade.prBodyNotes) { + try { + const res = handlebars + .compile(note)(upgrade) + .trim(); + if (res && res.length) { + notes.push(res); + } + } catch (err) { + logger.warn({ note }, 'Error compiling upgrade note'); + } + } + } + } + const uniqueNotes = [...new Set(notes)]; + prBody += uniqueNotes.join('\n\n'); + prBody += '\n\n'; + if (config.upgrades.some(upgrade => upgrade.gitRef)) { prBody += ':abcd: If you wish to disable git hash updates, add `":disableDigestUpdates"` to the extends array in your config.\n\n'; diff --git a/test/workers/pr/__snapshots__/index.spec.js.snap b/test/workers/pr/__snapshots__/index.spec.js.snap index 69a8009cf3e9100b7b15a31e003a0f8aae794226..32b395821dc6c4833f204dc1f89835e2d019ab42 100644 --- a/test/workers/pr/__snapshots__/index.spec.js.snap +++ b/test/workers/pr/__snapshots__/index.spec.js.snap @@ -120,6 +120,10 @@ Array [ | c | | | | | | d | | lockFileMaintenance | | | +note 1 + +note 2 + :abcd: If you wish to disable git hash updates, add \`\\":disableDigestUpdates\\"\` to the extends array in your config. :wrench: This Pull Request updates \`package.json\` lock files to use the latest dependency versions. diff --git a/test/workers/pr/index.spec.js b/test/workers/pr/index.spec.js index c1f947352b6e9b4467c848e5b0b030c6d151511b..c701e0069b38b8146400e34c8f7256d23ce7cbf5 100644 --- a/test/workers/pr/index.spec.js +++ b/test/workers/pr/index.spec.js @@ -158,6 +158,7 @@ describe('workers/pr', () => { { depName: 'a', newDigestShort: 'aaaaaaa', + prBodyNotes: ['note 1', 'note 2'], }, { depName: 'b', @@ -172,6 +173,7 @@ describe('workers/pr', () => { { depName: 'd', updateType: 'lockFileMaintenance', + prBodyNotes: ['{{#if foo}}'], }, ]); config.updateType = 'lockFileMaintenance'; diff --git a/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap b/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap index e85bd437dd2b09547e30ffd4f477e1a0038175e1..ae58066b0cae5a1445117a20441cf5600620fb6c 100644 --- a/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap +++ b/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap @@ -55,6 +55,7 @@ Array [ "Type": "{{{depType}}}", "Update": "{{{updateType}}}", }, + "prBodyNotes": Array [], "prConcurrentLimit": 0, "prCreation": "immediate", "prHourlyLimit": 0, @@ -141,6 +142,7 @@ Array [ "Type": "{{{depType}}}", "Update": "{{{updateType}}}", }, + "prBodyNotes": Array [], "prConcurrentLimit": 0, "prCreation": "immediate", "prHourlyLimit": 0, @@ -224,6 +226,7 @@ Array [ "Type": "{{{depType}}}", "Update": "{{{updateType}}}", }, + "prBodyNotes": Array [], "prConcurrentLimit": 0, "prCreation": "immediate", "prHourlyLimit": 0, @@ -313,6 +316,7 @@ Array [ "Type": "{{{depType}}}", "Update": "{{{updateType}}}", }, + "prBodyNotes": Array [], "prConcurrentLimit": 0, "prCreation": "immediate", "prHourlyLimit": 0, @@ -396,6 +400,7 @@ Array [ "Type": "{{{depType}}}", "Update": "{{{updateType}}}", }, + "prBodyNotes": Array [], "prConcurrentLimit": 0, "prCreation": "immediate", "prHourlyLimit": 0, @@ -485,6 +490,7 @@ Array [ "Type": "{{{depType}}}", "Update": "{{{updateType}}}", }, + "prBodyNotes": Array [], "prConcurrentLimit": 0, "prCreation": "immediate", "prHourlyLimit": 0, @@ -571,6 +577,7 @@ Array [ "Type": "{{{depType}}}", "Update": "{{{updateType}}}", }, + "prBodyNotes": Array [], "prConcurrentLimit": 0, "prCreation": "immediate", "prHourlyLimit": 0, @@ -657,6 +664,7 @@ Array [ "Type": "{{{depType}}}", "Update": "{{{updateType}}}", }, + "prBodyNotes": Array [], "prConcurrentLimit": 0, "prCreation": "immediate", "prHourlyLimit": 0, diff --git a/website/docs/configuration-options.md b/website/docs/configuration-options.md index 978ed72ae5c2cd8d5ee4528eb7b4b660d08d019f..ef961ad4fbc1b6979f04a019f97f689ca4110d9c 100644 --- a/website/docs/configuration-options.md +++ b/website/docs/configuration-options.md @@ -595,6 +595,18 @@ Here is an example of adding a custom "Sourcegraph" column definition: Note: Columns must also be included in the `prBodyColumns` array in order to be used, so that's why it's included above in the example. +## prBodyNotes + +Use this field to add custom content inside PR bodies, including conditionally. + +e.g. if you wish to add an extra Warning to major updates: + +```json +{ + "prBodyNotes": ["{{#if isMajor}}:warning: MAJOR MAJOR MAJOR :warning:{{/if}}"] +} +``` + ## prConcurrentLimit This setting - if enabled - limits Renovate to a maximum of x concurrent PRs open at any time.