From 85b2908c9d1e3563b3cae92a7fd99a0b7faa4391 Mon Sep 17 00:00:00 2001 From: Kasper Peulen <kasperpeulen@gmail.com> Date: Fri, 9 Jun 2023 15:49:33 +0200 Subject: [PATCH] Merge pull request #23009 from storybookjs/escape-pr-description Release: Fix not escaping content of GH Releases --- scripts/release/get-changelog-from-file.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/release/get-changelog-from-file.ts b/scripts/release/get-changelog-from-file.ts index 27b154d8d74e..78514d7a68af 100644 --- a/scripts/release/get-changelog-from-file.ts +++ b/scripts/release/get-changelog-from-file.ts @@ -14,9 +14,14 @@ program 'get changelog entry for specific version. If not version argument specified it will use the current version in code/package.json' ) .arguments('[version]') + .option('-E, --no-escape', 'Escape quote-like characters, so the output is safe in CLIs', true) .option('-V, --verbose', 'Enable verbose logging', false); -export const getChangelogFromFile = async (args: { version?: string; verbose?: boolean }) => { +export const getChangelogFromFile = async (args: { + version?: string; + escape?: boolean; + verbose?: boolean; +}) => { const version = args.version || (await getCurrentVersion()); const isPrerelease = semver.prerelease(version) !== null; const changelogFilename = isPrerelease ? 'CHANGELOG.prerelease.md' : 'CHANGELOG.md'; @@ -33,10 +38,16 @@ export const getChangelogFromFile = async (args: { version?: string; verbose?: b )}` ); } - const result = `## ${changelogForVersion}`; + const result = args.escape + ? `## ${changelogForVersion}` + .replaceAll('"', '\\"') + .replaceAll('`', '\\`') + .replaceAll("'", "\\'") + : `## ${changelogForVersion}`; console.log(dedent`📝 Changelog entry found: ${result}`); + if (process.env.GITHUB_ACTIONS === 'true') { setOutput('changelog', result); } @@ -45,7 +56,11 @@ export const getChangelogFromFile = async (args: { version?: string; verbose?: b if (require.main === module) { const parsed = program.parse(); - getChangelogFromFile({ version: parsed.args[0], verbose: parsed.opts().verbose }).catch((err) => { + getChangelogFromFile({ + version: parsed.args[0], + escape: parsed.opts().escape, + verbose: parsed.opts().verbose, + }).catch((err) => { console.error(err); process.exit(1); });