build: add action to automatically merge changelog.json on release PRs#8234
build: add action to automatically merge changelog.json on release PRs#8234
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a merge-changelog.cjs script and associated tests to automate the merging of changelog.json entries from pull requests. The script handles pull_request, push, and workflow_dispatch events. Review feedback identifies potential issues with GitHub API pagination in listFiles and pulls.list calls, recommending the use of github.paginate to ensure all files and pull requests are processed. It also suggests adding a trailing newline to the updated changelog.json for POSIX compliance.
| const response = await github.rest.pulls.listFiles({ | ||
| owner, | ||
| repo, | ||
| pull_number: prNumber, | ||
| }); | ||
| files = response.data; |
There was a problem hiding this comment.
The pulls.listFiles method is paginated and returns a limited number of files (default 30, max 100). If a pull request modifies many files, changelog.json might be missed if it's not in the first page of results. Using github.paginate ensures all files are checked.
files = await github.paginate(github.rest.pulls.listFiles, {
owner,
repo,
pull_number: prNumber,
});
|
|
||
| // Merge the changelogs | ||
| const mergedChangelog = mergeChangelogs(mainChangelog, prChangelog); | ||
| const newContent = JSON.stringify(mergedChangelog, null, 2); |
There was a problem hiding this comment.
It is a best practice for text files, including JSON, to end with a trailing newline. This prevents diff noise and adheres to POSIX standards. Since JSON.stringify does not include one, you should append it manually. This also ensures consistency if the original file already had a newline.
const newContent = JSON.stringify(mergedChangelog, null, 2) + '\n';
| const response = await github.rest.pulls.list({ | ||
| owner, | ||
| repo, | ||
| state: 'open', | ||
| }); | ||
| pulls = response.data; |
There was a problem hiding this comment.
The pulls.list method is paginated (default 30 items). If the repository has many open pull requests, some might be skipped during a push or workflow_dispatch event. Using github.paginate ensures all open PRs are processed.
pulls = await github.paginate(github.rest.pulls.list, {
owner,
repo,
state: 'open',
});
…update-changelog' into feywind-autoupdate-changelog
Many release PRs for handwritten/core created at once will result in the changelog.json file having conflicts in a way that's very difficult to merge through the GitHub UI. This adds an action workflow that does it for us.