Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit length of PR body to GH maximum (again) #96

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions packages/action/src/util/get-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => `
Expand All @@ -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);
Expand Down
Loading