diff --git a/lib/modules/platform/utils/__snapshots__/pr-body.spec.ts.snap b/lib/modules/platform/utils/__snapshots__/pr-body.spec.ts.snap index ebd9cd6f7b7b7cd93b82242d9bde7669bb61c5cf..e55cc69ffb3c90ee7435cd55e19e2560d94bdb08 100644 --- a/lib/modules/platform/utils/__snapshots__/pr-body.spec.ts.snap +++ b/lib/modules/platform/utils/__snapshots__/pr-body.spec.ts.snap @@ -33,9 +33,7 @@ exports[`modules/platform/utils/pr-body .smartTruncate truncates to 1000 1`] = ` ### [\`v19.47.0\`](https://togithub.com/renovatebot/renovate/releases/19.47.0) -##### Features - -- **docker:** AWS ECR authentication support ([#​4497](htt +##### Feat </details> diff --git a/lib/modules/platform/utils/pr-body.ts b/lib/modules/platform/utils/pr-body.ts index 371452e4bd2e48c91d140e467e2880d7635cced7..c3647402ae218d0305872bb8fbc747b5dcfc1fb0 100644 --- a/lib/modules/platform/utils/pr-body.ts +++ b/lib/modules/platform/utils/pr-body.ts @@ -1,23 +1,31 @@ -const re = new RegExp(`### Release Notes.*### Configuration`, 'ms'); +const re = new RegExp( + `(?<preNotes>.*### Release Notes)(?<releaseNotes>.*)### Configuration(?<postNotes>.*)`, + 's' +); export function smartTruncate(input: string, len: number): string { if (input.length < len) { return input; } - const releaseNotesMatch = re.exec(input); - if (releaseNotesMatch) { - const divider = `\n\n</details>\n\n---\n\n### Configuration`; - const [releaseNotes] = releaseNotesMatch; - const nonReleaseNotesLength = - input.length - releaseNotes.length - divider.length; - const availableLength = len - nonReleaseNotesLength; - if (availableLength <= 0) { - return input.substring(0, len); - } - return input.replace( - releaseNotes, - releaseNotes.slice(0, availableLength) + divider + + const reMatch = re.exec(input); + if (!reMatch) { + return input.substring(0, len); + } + + const divider = `\n\n</details>\n\n---\n\n### Configuration`; + const preNotes = reMatch.groups?.preNotes ?? ''; + const releaseNotes = reMatch.groups?.releaseNotes ?? ''; + const postNotes = reMatch.groups?.postNotes ?? ''; + + const availableLength = + len - (preNotes.length + postNotes.length + divider.length); + + if (availableLength <= 0) { + return input.substring(0, len); + } else { + return ( + preNotes + releaseNotes.slice(0, availableLength) + divider + postNotes ); } - return input.substring(0, len); }