Repository navigation
fix(vcs): stop the GitHub pull request webhook crashing on non-JSON file pages - #14168
Conversation
getPullRequestFiles merged every page body into the result without looking at the response. Adapter::call() only decodes application/json bodies, so a page that came back as anything else was a string and array_merge threw a TypeError. An error page with a JSON body was merged in as if it were a list of files. Throw on an HTTP error or a non-array body, as getPullRequest and the Gitea, GitLab and Bitbucket adapters already do. Ask for 100 files per page instead of 30: GitHub lists at most 3000 files, so a large pull request now takes 31 requests instead of 101.
…s fail to load The pull_request webhook and the external contribution authorize endpoint now catch a failed file listing, log a warning and continue with no affected files, like the getCommit call in the webhook. Path triggers are skipped without affected files, so the deployment still runs instead of the request failing. In the authorize endpoint a failure here came after the pull request id was saved, so every retry returned a 409.
🟢 Tier S · Ready to mergeThe pull request validates GitHub pull-request file responses and increases the page size to 100. GitHub webhook and external-contribution authorization handlers log file-fetch failures and continue without path filtering. It also adds a non-array response guard for Gitea and skips installation-specific GitHub calls in regions without a linked project. Latest changes: The newest commits separate GitHub HTTP and body errors, add the Gitea body guard, clarify fallback comments, and check for region-local projects before initializing GitHub adapters or fetching pull-request details.
📂 Walkthrough · 5
Reviewed the commits since |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…rror A page whose body is not decoded JSON now throws its own exception with code 0 and the status in the message, instead of reusing the HTTP status as the code. A 200 with an HTML body would otherwise carry code 200, which the error handler turns into a 500 that Sentry never sees. Gitea's getPullRequestFiles had the same unchecked array_merge, so a non-JSON page (for example an auth proxy's login page) raised the same TypeError. It now gets the same two checks.
… project Repositories and projects live in the shared platform database, and a webhook can reach every region, so each region looked up the linked repositories and, for pull requests, built the adapter, fetched the commit and listed every changed file before createGitDeployments skipped the projects hosted elsewhere. Building the adapter can mint an installation token. The push and pull_request handlers now load the repositories first and return before touching GitHub unless one of them belongs to a project in this region. The full list still goes to createGitDeployments, so the owning region behaves as before. Pull request events never build; they update the pull request comment and commit statuses. The fallback comments now say what an empty file list does there: path triggers can't filter, so resources are listed on the pull request whatever paths they watch.
|
@tenki-reviewer review |
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
The change makes GitHub/Gitea adapters validate pull-request file API responses before merging, raising GitHub's pagination page size to 100. The GitHub authorization update action now degrades gracefully when fetching affected PR files fails, logging a warning instead of aborting. The webhook event handler moves the linked-repositories lookup earlier and skips work early when no project in the current region is hosted.
Reviewed commit: 17b301e |
Security rulesNo new WARNING or ERROR findings from security rules. 32 existing findings tracked in
|
There was a problem hiding this comment.
Expand to see previous review
This PR hardens VCS pull-request file fetching with HTTP status and JSON validation, and adds region-aware early gating plus fail-safe error handling in the GitHub webhook and authorization flows.
Key findings
- 🟡 Fail-open path triggers when PR files fetch fails — Update.php:137
|
@tenki-reviewer review — the only finding is resolved as not applicable (see thread); please re-review the current head. |
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
The change raises pagination page sizes, adds error handling around pull-request file fetching, and introduces region-aware filtering in the GitHub events handler so only the owning region deploys resources. It also adjusts the PHPStan baseline for the vcs package.
Reviewed commit: 953e42c |
|
@hansi-codes review |
The GitHub
pull_requestwebhook crashed witharray_merge(): Argument #2 must be of type array, string giveninGitHub::getPullRequestFiles(). That madePOST /v1/vcs/github/eventsreturn 500 (206 Sentry events in a month on Cloud, all from regiontorin the sample).getPullRequestFiles()merged every page body without checking it.Adapter::call()only decodesapplication/json, so any other page stayed a string andarray_mergethrew. The PHPStan baseline was suppressing exactly this (array_merge expects array, mixed given).The trigger is a fork pull request that merges upstream
maininto the fork and changes about 5,478 files. It gets asynchronizeevent on every upstream push. GitHub lists at most 3000 files, so each event paged through 101 requests. Cloud forwards every GitHub webhook to every region, and repositories and projects live in the shared platform database. So every region built the adapter, fetched the commit and listed all the files, and only thencreateGitDeploymentsskipped the projects hosted elsewhere.Adapter (
packages/vcs)GitHub::getPullRequestFiles()throws on an HTTP error (code = status) or on a non-JSON body (code 0, status in the message, so it reaches Sentry and the log says what came back). It asks for 100 files per page, so the 3000-file cap now takes 31 requests instead of 101.Gitea::getPullRequestFiles()had the same uncheckedarray_mergeand gets the same two checks.Webhook (
GitHub/Events/Create.php)pull_requesthandlers load the linked repositories first. They return before building the adapter (which can mint an installation token) unless one of them belongs to a project in this region. The full list still goes tocreateGitDeployments, so the owning region behaves exactly as before.getCommit()call next to it. Pull request events never build: they update the PR comment and commit statuses. With no file list, path triggers can't filter, so resources are listed on the pull request whatever paths they watch. Before, nothing was posted and the webhook returned 500.Authorize endpoint (
GitHub/Authorize/External/Update.php)Test Plan
text/html502: the old adapter throws the exact productionTypeError; the new one throwsHTTP 502(code 502).text/html200: the new one throwsHTTP 200 returned a non-JSON body(code 0).HTTP 404.bin/monorepo check vcspasses and the vcs unit suite passes (128 tests). The regenerated baseline only removes the twoarray_mergeentries and moves counts for the existing status-code idiom. PHPStan and Pint pass on both app files.isProjectInCurrentRegion(), the check the installation handler already uses._APP_VCS_GITHUB_PRIVATE_KEY=disabled; 18 tests, 18 skipped on main).Not covered here
createComment,updateComment,getRepositoryName,generateAccessToken) still pass a possibly non-JSON body toarray_key_exists. They make one call each, not 101 per region, so they are less exposed.