From 272544a12b095af360e8d3bacfaacc13dcff4098 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 8 Mar 2023 23:22:36 +0000 Subject: [PATCH] chore: Update changelog script to respect code blocks --- scripts/changesets/changelog.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/changesets/changelog.js b/scripts/changesets/changelog.js index 08387bb5fe..70d4f02398 100644 --- a/scripts/changesets/changelog.js +++ b/scripts/changesets/changelog.js @@ -9,17 +9,15 @@ const TRAILING_CHAR = /[.;:]$/g; const listFormatter = new Intl.ListFormat('en-US'); const getSummaryLines = cs => { - const lines = cs.summary - .trim() - .split(/[\r\n]+/) - .map(l => l.trim()) - .filter(Boolean); - const size = lines.length; - if (size > 0) { - lines[size - 1] = lines[size - 1] - .replace(TRAILING_CHAR, ''); + let lines = cs.summary.trim().split(/\r?\n/); + if (!lines.some(line => /```/.test(line))) { + lines = lines.map(l => l.trim()).filter(Boolean); + const size = lines.length; + if (size > 0) { + lines[size - 1] = lines[size - 1] + .replace(TRAILING_CHAR, ''); + } } - return lines; }; @@ -111,8 +109,11 @@ const changelogFunctions = { str += `\n${futureLines.map(l => ` ${l}`).join('\n')}`; } - if (user) { + const endsWithParagraph = /(?<=(?:[!;?.]|```) *)$/g; + if (user && !endsWithParagraph) { str += `, by ${user}`; + } else { + str += `\nBy ${user}`; } if (pull || commit) {