Repository navigation
fix(vcs): reindex provider pull request ids after removing one - #13530
Conversation
array_diff() keeps the original keys, so untracking a pull request that is not the last entry leaves a gapped array. providerPullRequestIds is a declared array attribute, and the structure validator rejects any value that is not a list, so closing such a pull request threw instead of untracking it. Reindex at the three call sites that persist the result: the GitHub and Gitea event handlers, and the shared cleanup used by GitLab and Bitbucket. Teams membership listing had the same defect through array_filter(), which also preserves keys. Response::dynamic() writes each entry back to its original index, so a member with an empty userId in any but the last position turned the memberships list into a JSON object.
Greptile SummaryThis PR prevents key-preserving PHP filters from producing gapped arrays where list-shaped data is required.
Confidence Score: 5/5The PR appears safe to merge; the list reindexing fixes are correctly applied and the previously reported test race is resolved. No actionable defects or outstanding previous findings remain. The production changes preserve retained values and ordering while restoring list-shaped arrays, and the regression tests cover non-tail removal. Important Files Changed
Reviews (5): Last reviewed commit: "Merge branch 'main' into fix/vcs-pull-re..." | Re-trigger Greptile |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Meldiron
left a comment
There was a problem hiding this comment.
lgtm, lets see if we can add e2e test too
Closes #11741
What does this PR do?
array_diff()filters by value but keeps the original keys, so untracking a pull request that is not the last entry leaves a gapped array.The consequence is worse than malformed storage.
providerPullRequestIdsis declaredarray => trueinapp/config/collections/platform.php, and the structure validator rejects any value that is not a list:So closing an external contribution whose id sits anywhere but at the end throws, the webhook 500s, and the pull request is never untracked. Closing the last entry happens to work, which is why this went unnoticed.
Three call sites persist the result and all three are fixed:
VCS/Http/GitHub/Events/Create.php— the one reportedVCS/Http/Gitea/Events/Create.phpVcs/RepositoryPullRequestCleanup.php— shared by the GitLab and Bitbucket handlersSame bug elsewhere
Sweeping every key-preserving filter whose result is persisted or serialized turned up one more, in a different service:
Teams/Http/Memberships/XList.phpdrops memberships with an emptyuserIdthrougharray_filter(), which also preserves keys.Response::dynamic()writes each entry back to its original index rather than appending, so the gap survives into the response and a member with an emptyuserIdin any but the last position turns themembershipslist into a JSON object — breaking list deserialization in every SDK.Call sites where the filtered value is only used locally (
in_array,empty,count, iteration) were checked and left alone.Test Plan
tests/unit/Vcs/RepositoryPullRequestCleanupTest::testRemoveReindexesRemainingPullRequestIdsremoves a non-tail ID and asserts the persisted value is[2, 3].tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest::testClosePullRequestRemovesAuthorizationcreates two external pull requests through the local Gitea API and authorizes both through Appwrite. It closes and reopens the first, checks that it can be authorized again, and verifies the second remains authorized (duplicate authorization returns 409).Validated locally against the isolated Gitea fixture and real Appwrite API: the E2E passes with this fix and fails with HTTP 409 on reauthorization when only the Gitea
array_values()change is removed. Existing cleanup unit tests, Pint, and the focused Rector dry run also pass.