feat: Support push and merge_group events with use_rest_api - #2836
Conversation
Extend use_rest_api to work with push and merge_group events, not just pull_request*. For push events, uses repos.compareCommits with the before/after SHAs from the webhook payload. For merge_group, uses base_sha/head_sha. This allows skipping actions/checkout for large repos on these event types.
Not up to standards ⛔🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 36 |
| Duplication | 7 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
- Return empty results gracefully when push payload.before is the null SHA (force push or initial branch push) instead of letting the compareCommits API 404 - Add comment explaining why pulls.listFiles type is reused for compareCommits responses - Add test case for force push edge case
Use sparse-checkout to fetch only action.yml, then delete .git before running the action. This makes it explicit that the REST API path works without any local git history.
Move endpoint resolution logic into a dedicated function to flatten the if/else chain in getChangedFilesFromGithubAPI and address Codacy complexity warnings.
Without an explicit ref, the checkout action defaults to the fork's main branch instead of the PR head branch, causing eslint to fail when changed files only exist on the feature branch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Hey @jackton1 — I pushed a small fix to the CI The issue: The The fix: Added Let me know if you'd prefer a different approach or if there are repo conventions I should follow here — happy to adjust. |
|
Thanks, @npwolf. For this change, I'd need to do some more validation on my end, but nice work. |
This is fine |
|
@all-contributors please add @npwolf for code and test |
|
I've put up a pull request to add @npwolf! 🎉 |
4a737bb
into
tj-actions:test/push-and-merge-group-support
|
Thanks @jackton1 ! |
Closes #2835
Summary
use_rest_apimode to supportpushandmerge_groupevents, not justpull_request*pushevents, usesrepos.compareCommitswithpayload.before/payload.aftermerge_groupevents, usesrepos.compareCommitswithpayload.merge_group.base_sha/head_shapull_request*behavior is unchanged (still usespulls.listFiles)Motivation
Currently,
use_rest_api: trueworks onpull_requestevents but fails when the same workflow triggers onmerge_group(merge queue) orpush(landing on target branch). This forces users of large repos to either addactions/checkout(losing the performance benefit) or maintain separate workflow configurations per event type.The
repos.compareCommitsendpoint returns files in the same shape aspulls.listFiles, so all downstream processing (filtering, dir_names, output formatting, etc.) works without changes.Prior art
This pattern is proven in two maintained forks of jitterbit/get-changed-files:
pull_request,pull_request_target, andpushvia APIpull_request,pull_request_target,push, andmerge_groupvia APIChanges
src/changedFiles.tsgetChangedFilesFromGithubAPIby event typesrc/main.tssrc/__tests__/changedFiles.test.tssrc/__tests__/main.test.tsdist/,lib/Test plan
use_rest_api: trueLimitations
The same 3,000-file cap that applies to
pulls.listFilesalso applies torepos.compareCommits. This is a GitHub API limitation.