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`] = ` ...@@ -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) ### [\`v19.47.0\`](https://togithub.com/renovatebot/renovate/releases/19.47.0)
##### Features ##### Feat
- **docker:** AWS ECR authentication support ([#&#8203;4497](htt
</details> </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 { export function smartTruncate(input: string, len: number): string {
if (input.length < len) { if (input.length < len) {
return input; return input;
} }
const releaseNotesMatch = re.exec(input);
if (releaseNotesMatch) { const reMatch = re.exec(input);
const divider = `\n\n</details>\n\n---\n\n### Configuration`; if (!reMatch) {
const [releaseNotes] = releaseNotesMatch; return input.substring(0, len);
const nonReleaseNotesLength = }
input.length - releaseNotes.length - divider.length;
const availableLength = len - nonReleaseNotesLength; const divider = `\n\n</details>\n\n---\n\n### Configuration`;
if (availableLength <= 0) { const preNotes = reMatch.groups?.preNotes ?? '';
return input.substring(0, len); const releaseNotes = reMatch.groups?.releaseNotes ?? '';
} const postNotes = reMatch.groups?.postNotes ?? '';
return input.replace(
releaseNotes, const availableLength =
releaseNotes.slice(0, availableLength) + divider 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