Skip to content
Snippets Groups Projects
Unverified Commit f730ff53 authored by MaronHatoum's avatar MaronHatoum Committed by GitHub
Browse files

fix(platform/pr-body): refactor smartTruncate function (#14915)


Co-authored-by: default avatarRhys Arkins <rhys@arkins.net>
parent 979de8d8
No related branches found
No related tags found
No related merge requests found
......@@ -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 ([#&#8203;4497](htt
##### Feat
</details>
......
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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment