diff --git a/src/renderer/src/components/right-sidebar/source-control-manual-review-url.test.ts b/src/renderer/src/components/right-sidebar/source-control-manual-review-url.test.ts index bae8edb68..c35b60d3c 100644 --- a/src/renderer/src/components/right-sidebar/source-control-manual-review-url.test.ts +++ b/src/renderer/src/components/right-sidebar/source-control-manual-review-url.test.ts @@ -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({ diff --git a/src/renderer/src/components/right-sidebar/source-control-manual-review-url.ts b/src/renderer/src/components/right-sidebar/source-control-manual-review-url.ts index fd65f3b47..4b5f44227 100644 --- a/src/renderer/src/components/right-sidebar/source-control-manual-review-url.ts +++ b/src/renderer/src/components/right-sidebar/source-control-manual-review-url.ts @@ -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 })