fix(gitlab): open the New-MR page on the fork project for fork-pushed branches (#7654)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mark Xian
2026-07-23 23:10:54 -07:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 9373f5d37a
commit afa549f1d2
2 changed files with 26 additions and 1 deletions
@@ -137,6 +137,26 @@ describe('buildSourceControlManualReviewUrl', () => {
)
})
it('opens the GitLab New-MR page on the fork project when the branch was pushed to a fork', () => {
expect(
buildSourceControlManualReviewUrl({
baseRef: 'refs/remotes/upstream/main',
branchName: 'feature/fork-head',
repoRemoteName: 'upstream',
repoRemoteUrl: 'git@gitlab.company.test:group/sub/orca.git',
provider: 'gitlab',
pushTarget: {
remoteName: 'fork',
branchName: 'feature/fork-head',
remoteUrl: 'git@gitlab.company.test:contributor/orca.git'
}
})
// On the fork project — not group/sub/orca, where source_branch would 404.
).toBe(
'https://gitlab.company.test/contributor/orca/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Ffork-head&merge_request%5Btarget_branch%5D=main'
)
})
it('builds a Bitbucket manual pull request URL', () => {
expect(
buildSourceControlManualReviewUrl({
@@ -169,7 +169,12 @@ export function buildSourceControlManualReviewUrl(input: ManualReviewUrlInput):
githubHeadRef(baseRepo, headRepo, headBranch)
)}?expand=1`
case 'gitlab':
return appendQuery(`${baseRepo.webBaseUrl}/-/merge_requests/new`, {
// Why: the source branch lives in the head repo, so the New-MR page must
// be opened on that project — a fork's branch is invisible to the base
// project and its /-/merge_requests/new page would 404 the source_branch.
// GitLab defaults the target to the fork's upstream. headRepo === baseRepo
// for the non-fork case, so this is a no-op there.
return appendQuery(`${headRepo.webBaseUrl}/-/merge_requests/new`, {
'merge_request[source_branch]': headBranch,
'merge_request[target_branch]': baseBranch
})