fix: github PR body max length#157
Conversation
🦋 Changeset detectedLatest commit: 8d5da5c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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; |
There was a problem hiding this comment.
Since we have prBodyPromise, this variable probably should be called prBody to make the connection between them obvious.
src/run.ts
Outdated
| messageBody = [ | ||
| messageBody.substring(0, MAX_CHARACTERS_PER_MESSAGE), | ||
| "[Too long, message truncated]", | ||
| ].join("\n\n"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I think it's safer to start with the suggested way.
We'd have to just move this part to compute a separate object:
Line 245 in 7e613b3
and construct the final body later with the algorithm like:
- prepare the message without considering the limit
- 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
There was a problem hiding this comment.
@Andarist I pushed some changes following your suggestions. It would be nice if you can take a look when you have time.
Thanks
61ae721 to
a01e812
Compare
src/run.ts
Outdated
| preState?: PreState; | ||
| }; | ||
|
|
||
| export async function getChangesetsMessage({ |
There was a problem hiding this comment.
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, |
src/run.ts
Outdated
| content: entry.content, | ||
| header: `## ${pkg.packageJson.name}@${pkg.packageJson.version}`, |
There was a problem hiding this comment.
These information have been split into two fields now.
src/run.ts
Outdated
| // Check (again) that the message is within the size limit. | ||
| // If not, omit all release content this time. | ||
| if (fullMessage.length > maxCharactersPerMessage) { |
There was a problem hiding this comment.
heh, this is probably very, very unlikely :P but I appreciate thinking about this edge case 👍
src/run.ts
Outdated
| ⚠️⚠️⚠️⚠️⚠️⚠️ | ||
| ` | ||
| : ""; | ||
| let messageReleases = `# Releases`; |
There was a problem hiding this comment.
nit:
| let messageReleases = `# Releases`; | |
| let messageReleasesHeading = `# Releases`; |
src/run.ts
Outdated
| prTitle?: string; | ||
| commitMessage?: string; | ||
| hasPublishScript?: boolean; | ||
| maxCharactersPerMessage?: number; |
There was a problem hiding this comment.
nit:
| maxCharactersPerMessage?: number; | |
| prBodyMaxCharacters?: number; |
src/run.ts
Outdated
| preState?: PreState; | ||
| }; | ||
|
|
||
| export async function getChangesetsMessage({ |
There was a problem hiding this comment.
nit:
| export async function getChangesetsMessage({ | |
| export async function getVersionPrBody({ |
src/run.ts
Outdated
| }); | ||
| let changedPackages = await getChangedPackages(cwd, versionsByDirectory); | ||
| let changedPackagesInfo = ( | ||
| await Promise.all( |
There was a problem hiding this comment.
nit: previously this was parallelized, we could maintain this with:
| await Promise.all( | |
| Promise.all( |
a01e812 to
6220154
Compare
|
@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 |
|
Btw, here's a real example of how this looks when the content is reduced. |
|
@Andarist Friendly reminder in case you haven't had a chance to look at the final changes. Thanks |
|
@Andarist Awesome, thanks! |
|
This solution only fixes the generated Version PR body exceeding the max body length. The problem still exists for creating GitHub releases: The failing action run: https://github.com/tedraykov/reaction/actions/runs/3196539005/jobs/5218616158#step:7:163 |
|
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. |
…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>
I had an issue today where the PR body exceeded a size limit.
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: