diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index 6ce7ef36337a7928bd411d378ac00289fe1d56f1..8264c019d05d2d45c14cf836e631dbcb4ebf9066 100644 --- a/lib/platform/github/index.js +++ b/lib/platform/github/index.js @@ -1314,20 +1314,41 @@ async function mergePr(prNo, branchName) { return true; } +// istanbul ignore next +function smartTruncate(input) { + if (input.length < 60000) { + return input; + } + const releaseNotesMatch = input.match( + /### Release Notes.*### Renovate configuration/ms + ); + // istanbul ignore if + if (releaseNotesMatch) { + const divider = '</details>\n\n---\n\n### Renovate configuration'; + const [releaseNotes] = releaseNotesMatch; + const nonReleaseNotesLength = + input.length - releaseNotes.length - divider.length; + const availableLength = 60000 - nonReleaseNotesLength; + return input.replace( + releaseNotes, + releaseNotes.slice(0, availableLength) + divider + ); + } + return input.substring(0, 60000); +} + function getPrBody(input) { if (config.isGhe) { - return input.substring(0, 60000); + return smartTruncate(input); } - return ( - input - // to be safe, replace all github.com links with renovatebot redirector - .replace( - /href="https?:\/\/github.com\//g, - 'href="https://renovatebot.com/gh/' - ) - .replace(/]\(https:\/\/github\.com\//g, '](https://renovatebot.com/gh/') - .substring(0, 60000) - ); + const massagedInput = input + // to be safe, replace all github.com links with renovatebot redirector + .replace( + /href="https?:\/\/github.com\//g, + 'href="https://renovatebot.com/gh/' + ) + .replace(/]\(https:\/\/github\.com\//g, '](https://renovatebot.com/gh/'); + return smartTruncate(massagedInput); } async function getVulnerabilityAlerts() {