Skip to content

fix(source-control): route nested GitLab merge requests before GitHub prefix matches - #46560

Open
saphid wants to merge 1 commit into
pingdotgg:mainfrom
saphid:hunter/c-ed044f12a2
Open

saphid wants to merge 1 commit into
pingdotgg:mainfrom
saphid:hunter/c-ed044f12a2

Conversation

@saphid

@saphid saphid commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Problem

A GitLab merge request link opens the wrong repository and request number when a project path has a /pull/<n>/ segment, as with a nested group named pull. The built-in registry stops at the first host that parses a link, and GitHub's /<owner>/<repo>/pull/<n>/ route matches before GitLab's more specific /-/merge_requests/<n> route. This affects in-app PR link targets on web, desktop and mobile (resolveChangeRequestLinkTarget → sourceControlClients.parseChangeRequestUrl) and the server's thread PR sync, which uses the same registry.

Deterministic repro on origin/main (f875b27e5a0cea608918fa21bbb955471276037a): call builtInSourceControlDefinitions.parseChangeRequestUrl("https://gitlab.com/acme/team/pull/123/-/merge_requests/7"), then try again with host forge.example. Alternatively, call resolveChangeRequestLinkTarget with a GitLab project whose canonicalKey is gitlab.com/acme/team/pull/123. No forge network call is needed.

  • Observed: kind: "github", repository: "acme/team", number: 123 on both hosts, so resolveChangeRequestLinkTarget returns null for the matching GitLab project.
  • Expected: kind: "gitlab", repository: "acme/team/pull/123", number: 7.

Change

Add GitLab to the built-in registry's claimChangeRequestUrlsFirst list so its /-/ routes are tried before GitHub's routes, which accept any hostname. GitLab's routes all need a /-/ segment, which GitHub does not use, so ordinary GitHub links still parse as before. The same claim order also applies to issue, commit and autolink parsing, where GitLab's /-/ routes are just as specific.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • Added two cases to packages/client-runtime/src/changeRequestLinks.test.ts. The first resolves a nested GitLab MR on gitlab.com and forge.example. The second checks that a GitHub PR subpage (/pull/7/files) still parses as GitHub's.
  • On base, vp test run src/changeRequestLinks.test.ts fails the first case (AssertionError: expected null to deeply equal { host: "gitlab.com", repository: "acme/team/pull/123", number: 7, … }; 1 failed, 14 passed). On head, all 15 pass.
  • vp run check:changed exits 0 (format, lint, knip, typecheck, affected tests).
  • Before/after registry transcript: https://gist.github.com/saphid/23bda84ca3114141587aff3b53cc711c

Not shown: no screenshots, because no rendered UI changed. I did not open a link in a running client or use a live GitLab instance.

Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • apps/web/src/lib/openPullRequestLink.ts:278 — The transcript proves parser and target behavior, not a running-client click. Make the repro scenario-ready: load a matching GitLab project with in-app link opening enabled, click the MR from thread text, and assert that the native panel targets acme/team/pull/123 MR !7 instead of falling through to generic link handling. No real-client or live-forge run was performed.
  • scripts/check-changed.ts:328 — The head-tagged gist reports a clean check:changed run but does not include the command output or exit status capture. Attach SHA-stamped output for independent verification; the read-only review did not rerun the full command.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Dec 1, 2026
@macroscopeapp

macroscopeapp Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at c3d2039

Macroscope's review found this PR approvable — GitLab merge-request URLs are now recognized before overlapping GitHub URL prefixes. The change is limited to link routing and leaves the default client and remote recognition unchanged.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The registry now checks GitLab before GitHub when claiming change-request URLs. New tests cover nested GitLab project paths containing /pull/ and GitHub pull-request /files URLs.

Changes: Change-request URL resolution

Layer / File(s) Summary
Provider precedence and resolution coverage
packages/source-control-definitions/src/registry.ts, packages/client-runtime/src/changeRequestLinks.test.ts
The registry adds GitLab after Azure DevOps in claimChangeRequestUrlsFirst. Tests cover nested GitLab merge-request URLs on gitlab.com and a custom host, plus GitHub pull-request /files URL resolution.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to c3d20

Nested GitLab merge-request links should now resolve to the right project, and ordinary GitHub pull-request links should keep resolving as before. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: GitLab nested merge-request URLs are routed before GitHub prefix matches. The changeset adds GitLab to claimChangeRequestUrlsFirst in the registry, with tests for nest…
Description check Passed The description follows the template. It has Problem, Change, Scope, and Verification sections, and it explains the root cause, the fix, and the tests. The Verification section gives a test result (1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: GitLab nested merge-request URLs are routed before GitHub prefix matches. The changeset adds GitLab to claimChangeRequestUrlsFirst in the registry, with tests for nested GitLab MR links and a GitHub PR subpage regression. The title uses the conventional commit format and is 84 characters long, which is acceptable.

Full details: Description check

Explanation

The description follows the template. It has Problem, Change, Scope, and Verification sections, and it explains the root cause, the fix, and the tests. The Verification section gives a test result (1 failed and 14 passed on base, 15 passed on head) and a check:changed exit status. It does not include screenshots, but the description explains why none apply because no rendered UI changed. The author also states that the change does not rely on a running client or a live GitLab instance.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between adf6562 and c3d2039.

Files selected for processing: 2

  • packages/client-runtime/src/changeRequestLinks.test.ts
  • packages/source-control-definitions/src/registry.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). takeover:in-progress A takeover lead is working on this PR vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants