From 5c8d28c55a69ac5ba310f7247047363fcfb5cc72 Mon Sep 17 00:00:00 2001 From: Sergei Chestakov Date: Fri, 21 Jun 2024 11:15:52 -0400 Subject: [PATCH] Limit length of PR body to GH maximum (again) (#96) Attempt num 2 since the first time didn't work: https://github.com/whopio/turbo-module/pull/92 CI in apps-monorepo is failing bc the PR body's we generate exceed GH's limit. --- packages/action/src/util/get-message.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/action/src/util/get-message.ts b/packages/action/src/util/get-message.ts index 75adedb..5208765 100644 --- a/packages/action/src/util/get-message.ts +++ b/packages/action/src/util/get-message.ts @@ -9,9 +9,10 @@ const capitalise = (str: string) => // GitHub enforces a max length of 65536 characters for a pull request body const maxLength = 65536; +const lengthBuffer = 1000; -export const makeGithubReleaseMessage = (stats: ReleaseStats) => - ` +export const makeGithubReleaseMessage = (stats: ReleaseStats) => { + const message = ` ${Object.entries(stats.pulls) .map( ([key, pulls]) => ` @@ -25,9 +26,17 @@ ${pulls.map(({ title }) => `- ${title}`).join('\n')} ${Array.from(stats.authors) .map((author) => `@${author}`) .join(', ')} -` - .trim() - .slice(0, maxLength); +`.trim(); + + if (message.length >= maxLength - lengthBuffer) { + return `${message.slice( + 0, + maxLength - lengthBuffer, + )}...\nThis message has been truncated to avoid exceeding the GitHub API's body limit.`; + } + + return message; +}; const getReleaseMessage = async (prerelease: boolean) => { const latestRelease = await getLatestRelease(prerelease);