Skip to content

feat: Support push and merge_group events with use_rest_api#2836

Open
npwolf wants to merge 6 commits intotj-actions:mainfrom
npwolf:feat/rest-api-push-merge-group
Open

feat: Support push and merge_group events with use_rest_api#2836
npwolf wants to merge 6 commits intotj-actions:mainfrom
npwolf:feat/rest-api-push-merge-group

Conversation

@npwolf
Copy link
Copy Markdown

@npwolf npwolf commented Mar 31, 2026

Closes #2835

Summary

  • Extends use_rest_api mode to support push and merge_group events, not just pull_request*
  • For push events, uses repos.compareCommits with payload.before/payload.after
  • For merge_group events, uses repos.compareCommits with payload.merge_group.base_sha/head_sha
  • Existing pull_request* behavior is unchanged (still uses pulls.listFiles)
  • No changes to the git-based code path or any existing inputs/outputs

Motivation

Currently, use_rest_api: true works on pull_request events but fails when the same workflow triggers on merge_group (merge queue) or push (landing on target branch). This forces users of large repos to either add actions/checkout (losing the performance benefit) or maintain separate workflow configurations per event type.

The repos.compareCommits endpoint returns files in the same shape as pulls.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:

Changes

File Change
src/changedFiles.ts Branch endpoint selection in getChangedFilesFromGithubAPI by event type
src/main.ts Allow push/merge_group through to the REST API path
src/__tests__/changedFiles.test.ts New: 9 unit tests for API function (existing + new event types)
src/__tests__/main.test.ts New: 4 unit tests for routing logic
dist/, lib/ Rebuilt

Test plan

  • All 13 new unit tests pass
  • All pre-existing tests unaffected
  • TypeScript compiles cleanly
  • Lint passes with zero warnings
  • E2E: test with a real push event workflow using use_rest_api: true

Limitations

The same 3,000-file cap that applies to pulls.listFiles also applies to repos.compareCommits. This is a GitHub API limitation.

npwolf added 2 commits March 31, 2026 09:09
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.
@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Mar 31, 2026

Not up to standards ⛔

🔴 Issues 2 medium

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
Complexity 2 medium

View in Codacy

🟢 Metrics 36 complexity . 7 duplication

Metric Results
Complexity 36
Duplication 7

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

npwolf added 4 commits March 31, 2026 09:45
- 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.
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.

feat: Support push and merge_group events with use_rest_api

1 participant