Skip to content

fix: github PR body max length#157

Merged
Andarist merged 8 commits intochangesets:mainfrom
emmenko:nm-fix-body-max-length
May 10, 2022
Merged

fix: github PR body max length#157
Andarist merged 8 commits intochangesets:mainfrom
emmenko:nm-fix-body-max-length

Conversation

@emmenko
Copy link
Contributor

@emmenko emmenko commented Mar 4, 2022

I had an issue today where the PR body exceeded a size limit.

image

This prevents the PR to be created.

To fix that we can truncate the message if we detect it's too long.

Let me know what you think and if I need to add a test for this use case.

This is how the truncated message in the PR looks like:

image

@changeset-bot
Copy link

changeset-bot bot commented Mar 4, 2022

🦋 Changeset detected

Latest commit: 8d5da5c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@changesets/action Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

src/run.ts Outdated
let searchResult = await searchResultPromise;
console.log(JSON.stringify(searchResult.data, null, 2));

let messageBody = await prBodyPromise;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have prBodyPromise, this variable probably should be called prBody to make the connection between them obvious.

src/run.ts Outdated
Comment on lines +293 to +296
messageBody = [
messageBody.substring(0, MAX_CHARACTERS_PER_MESSAGE),
"[Too long, message truncated]",
].join("\n\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the potential of breaking some formatting stuff or breaking links etc (which has probably happened on the attached screenshot). I wonder if on such an occasion, we shouldn't just replace the whole "changelogs" part with a placeholder message explaining the problem and advising to read the git diff, we could even construct a link to the "File Changed" tab there. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, formatting might be broken. I don't have a strong opinion to be honest.
The important part is that the PR is opened without errors, as otherwise the release is blocked.

Up to you to decide.

Copy link
Member

@Andarist Andarist Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safer to start with the suggested way.

We'd have to just move this part to compute a separate object:

await Promise.all(

and construct the final body later with the algorithm like:

  1. prepare the message without considering the limit
  2. if the limit has been exceeded then construct a fallback body that would have those things in it:
  • "this preface"
  • information that the limit has been exceeded
  • list of releases (names + versions, similar to what we already print in the full body, just without the changelog part

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Andarist I pushed some changes following your suggestions. It would be nice if you can take a look when you have time.
Thanks

@emmenko emmenko force-pushed the nm-fix-body-max-length branch from 61ae721 to a01e812 Compare March 7, 2022 20:26
src/run.ts Outdated
preState?: PreState;
};

export async function getChangesetsMessage({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted the logic to construct the message into a separate function.

src/run.ts Outdated
prTitle = "Version Packages",
commitMessage = "Version Packages",
hasPublishScript = false,
maxCharactersPerMessage = MAX_CHARACTERS_PER_MESSAGE,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful for testing

src/run.ts Outdated
Comment on lines +310 to +311
content: entry.content,
header: `## ${pkg.packageJson.name}@${pkg.packageJson.version}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These information have been split into two fields now.

@Andarist Andarist linked an issue Apr 15, 2022 that may be closed by this pull request
src/run.ts Outdated
Comment on lines +233 to +235
// Check (again) that the message is within the size limit.
// If not, omit all release content this time.
if (fullMessage.length > maxCharactersPerMessage) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, this is probably very, very unlikely :P but I appreciate thinking about this edge case 👍

src/run.ts Outdated
⚠️⚠️⚠️⚠️⚠️⚠️
`
: "";
let messageReleases = `# Releases`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
let messageReleases = `# Releases`;
let messageReleasesHeading = `# Releases`;

src/run.ts Outdated
prTitle?: string;
commitMessage?: string;
hasPublishScript?: boolean;
maxCharactersPerMessage?: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
maxCharactersPerMessage?: number;
prBodyMaxCharacters?: number;

src/run.ts Outdated
preState?: PreState;
};

export async function getChangesetsMessage({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
export async function getChangesetsMessage({
export async function getVersionPrBody({

src/run.ts Outdated
});
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
let changedPackagesInfo = (
await Promise.all(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: previously this was parallelized, we could maintain this with:

Suggested change
await Promise.all(
Promise.all(

@emmenko emmenko force-pushed the nm-fix-body-max-length branch from a01e812 to 6220154 Compare April 20, 2022 08:36
@emmenko emmenko requested a review from Andarist April 20, 2022 08:36
@emmenko
Copy link
Contributor Author

emmenko commented Apr 20, 2022

@Andarist Hi 👋, I applied your suggestions and rebased the branch.

I think this should be good to go now, unless you have other suggestions. Thanks

@emmenko
Copy link
Contributor Author

emmenko commented Apr 20, 2022

Btw, here's a real example of how this looks when the content is reduced.

commercetools/ui-kit#2178

@emmenko
Copy link
Contributor Author

emmenko commented May 10, 2022

@Andarist Friendly reminder in case you haven't had a chance to look at the final changes. Thanks

@Andarist Andarist merged commit 521c27b into changesets:main May 10, 2022
@github-actions github-actions bot mentioned this pull request May 10, 2022
@emmenko emmenko deleted the nm-fix-body-max-length branch May 11, 2022 13:21
@emmenko
Copy link
Contributor Author

emmenko commented May 11, 2022

@Andarist Awesome, thanks!

@tedraykov
Copy link

This solution only fixes the generated Version PR body exceeding the max body length. The problem still exists for creating GitHub releases:

Error: Validation Failed: {"resource":"Release","code":"custom","field":"body","message":"body is too long (maximum is 125000 characters)"}

The failing action run: https://github.com/tedraykov/reaction/actions/runs/3196539005/jobs/5218616158#step:7:163

@Andarist
Copy link
Member

Andarist commented Oct 6, 2022

My educated guess here is that we could detect the format of this CHANGELOG correctly and thus the whole thing was passed as the github release body in the payload. This is a problem on its own. Exceeding the character limit with legitimate requests is possible but very unlikely.

@davenicoll davenicoll mentioned this pull request Oct 18, 2022
9 tasks
cometkim pushed a commit to cometkim/yarn-changeset-action that referenced this pull request Apr 11, 2023
…60k characters by omitting some of the changelog information (changesets#157)

* fix: body max length

* docs: improve logs

* docs: changeset

* refactor: changeset message to omit some info if message exceeds size limit

* refactor: minor adjustments based on feedback

* Apply nits from code review

* Fixed tests

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

body is too long (maximum is 65536 characters)

3 participants