Repository navigation
fix(gitlab): find merge requests opened from a fork - #40894
juliusmarminge merged 4 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Listing a branch's merge requests from the upstream itself looked up every fork's source project, one glab call each, though none of them can match. GitLab's head probe now keeps the owner-qualified selector GitManager sends first for a fork head, and only that list resolves source project ids, once per distinct id and concurrently. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EvidenceCreated a real GitLab fork MR from feature/x into upstream main. Opened the same branch in fresh web app state on both commits and invoked create_pr. Base missed the MR; head displayed it and returned opened_existing. Chromium, 1280×800, light theme, replay-agent history.
Limitation: base's Create MR action stopped at disabled text generation, so the original duplicate-MR error was not captured. Discovery failure and head's reuse result were verified. Not shown:
|
Co-authored-by: Abhiram-745 <237478249+Abhiram-745@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>


Problem
On GitLab, T3 Code never finds a merge request opened from a fork.
Repro on
main:originis the upstream (group/upstream), and add your fork as another remote (alice/upstream).feature/x, push it to the fork, and open a merge request into the upstream project (from T3 Code or the GitLab UI).GitLabCli.listMergeRequestsrunsglab mr list --source-branch <branch> --output json. glab prints GitLab's merge request list rows (client-goBasicMergeRequest), which name the source project only bysource_project_id. There is nosource_projectobject in that output, and the GitLab MR API docs list none.normalizeGitLabMergeRequestRecordreadsraw.source_project, so a fork MR comes back withisCrossRepository: truebut noheadRepositoryNameWithOwnerorheadRepositoryOwnerLogin.matchesBranchHeadContextinGitManager.tsthen rejects every cross-repository MR whose head has neither, so both the status lookup and the existing-MR check before create miss it. The existing tests pass only because their fixtures include asource_projectfield that glab doesn't print.Change
GitLabClilooks the project up once withglab api projects/<source_project_id>and fillsheadRepositoryNameWithOwnerandheadRepositoryOwnerLoginfrom itspath_with_namespace, using the existing owner rule.source_project, cause no extra glab call and come out unchanged.Scope
This is a focused fix for an obvious bug in the GitLab adapter, so I didn't open an issue. #29791 made GitLab read a full page so
GitManager's owner matching could pick the branch's own MR out of fork MRs, but that matching needs the source project, which real glab output doesn't include. #23439 changed fork MR creation, not the lookup.Verification
GitLabSourceControlProvider.git.test.ts, "names a fork merge request's source project from real glab list output". It lists four MRs in the real glab shape: two forks from one project, one same-project MR, and a fork whose project lookup returns bad JSON. Onmainit fails withexpected [ { provider: 'gitlab', …(11) }, …(3) ] to match object [ { number: 1, …(3) }, …(3) ]. With the fix it passes, and it asserts the onlyglab apicalls areprojects/101andprojects/102: one per project, none for the same-project MR.packages/source-control-gitlabpasses (296 tests).apps/serverGitManager.test.tspasses (160 tests).vp fmt,vp lintandknip:checkon the changed files are clean, and the package typecheck passes.mr listJSON (client-goBasicMergeRequest) and the GitLab merge request API docs.Code written with Claude Code (Claude Opus 5.5).