feat: Support push and merge_group events with use_rest_api#2836
Open
npwolf wants to merge 6 commits intotj-actions:mainfrom
Open
feat: Support push and merge_group events with use_rest_api#2836npwolf wants to merge 6 commits intotj-actions:mainfrom
npwolf wants to merge 6 commits intotj-actions:mainfrom
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
|
| Category | Results |
|---|---|
| Complexity | 2 medium |
🟢 Metrics 36 complexity . 7 duplication
Metric Results Complexity 36 Duplication 7
TIP This summary will be updated as you push new changes. Give us feedback
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.