Let hosted review links open in the system browser (#5564)

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Brennan Benson
2026-06-17 14:04:25 -07:00
committed by GitHub
co-authored by Orca
parent 18d3545bae
commit 874988ddff
6 changed files with 268 additions and 23 deletions
@@ -1,6 +1,6 @@
import { type ReactNode } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ChecksPanelReviewHeader } from './ChecksPanel'
vi.mock('@/components/ui/dropdown-menu', () => ({
@@ -19,12 +19,22 @@ vi.mock('@/components/ui/dropdown-menu', () => ({
}) => <div data-disabled={disabled ? 'true' : undefined}>{children}</div>
}))
beforeEach(() => {
vi.stubGlobal('navigator', { userAgent: 'Macintosh' })
})
afterEach(() => {
vi.unstubAllGlobals()
})
function renderHeader({
canUnlinkPullRequest = true,
provider = 'github'
provider = 'github',
showSystemBrowserHint = true
}: {
canUnlinkPullRequest?: boolean
provider?: 'github' | 'gitlab'
showSystemBrowserHint?: boolean
} = {}): string {
const isGitLab = provider === 'gitlab'
return renderToStaticMarkup(
@@ -43,6 +53,7 @@ function renderHeader({
}}
isRefreshing={false}
canUnlinkPullRequest={canUnlinkPullRequest}
showSystemBrowserHint={showSystemBrowserHint}
onRefresh={vi.fn()}
onOpenReview={vi.fn()}
onUnlinkPullRequest={vi.fn()}
@@ -56,6 +67,9 @@ describe('ChecksPanelReviewHeader', () => {
const markup = renderHeader()
expect(markup).toContain('Open on GitHub')
expect(markup).toContain('system browser')
expect(markup).toContain('⇧⌘+click')
expect(markup).not.toContain('⌘+click to open')
expect(markup).toContain('#2964')
expect(markup).toContain('underline decoration-border underline-offset-2')
expect(markup).toContain('More PR actions')
@@ -65,6 +79,23 @@ describe('ChecksPanelReviewHeader', () => {
expect(markup).not.toContain('lucide-external-link')
})
it('omits the system-browser hint when plain clicks already open externally', () => {
const markup = renderHeader({ showSystemBrowserHint: false })
expect(markup).toContain('Open on GitHub')
expect(markup).not.toContain('system browser')
expect(markup).not.toContain('⇧⌘+click')
})
it('shows the Ctrl system-browser hint off macOS', () => {
vi.stubGlobal('navigator', { userAgent: 'Windows' })
const markup = renderHeader()
expect(markup).toContain('Shift+Ctrl+click for system browser')
expect(markup).not.toContain('Ctrl+click to open')
})
it('disables unlinking when the displayed PR is not manually linked', () => {
const markup = renderHeader({ canUnlinkPullRequest: false })
@@ -24,6 +24,10 @@ import { cn } from '@/lib/utils'
import { openHttpLink } from '@/lib/http-link-routing'
import { Button } from '@/components/ui/button'
import { DetachedHeadBadge } from '@/components/DetachedHeadBadge'
import {
getTerminalUrlSystemBrowserHint,
isMacPlatform
} from '../terminal-pane/terminal-link-open-hints'
import {
DropdownMenu,
DropdownMenuContent,
@@ -135,6 +139,7 @@ import { stripBaseRef, useCreatePullRequestDialogFields } from './useCreatePullR
import { localizedHostedReviewCopy } from '@/i18n/hosted-review-localized-copy'
import { translate } from '@/i18n/i18n'
import { groupPRComments, type PRCommentGroup } from '@/lib/pr-comment-groups'
import { openChecksPanelHostedReviewUrl } from './checks-panel-hosted-review-click-routing'
const RUNTIME_SSH_STATUS_REFRESH_MS = 3000
const GIT_STATUS_FAILURE_RETRY_MS = 3000
@@ -164,8 +169,9 @@ type ChecksPanelReviewHeaderProps = {
review: ChecksPanelReview
isRefreshing: boolean
canUnlinkPullRequest: boolean
showSystemBrowserHint: boolean
onRefresh: () => void
onOpenReview: () => void
onOpenReview: (event: React.MouseEvent<HTMLButtonElement>) => void
onUnlinkPullRequest: () => void
onLinkAnotherPullRequest: () => void
}
@@ -174,6 +180,7 @@ export function ChecksPanelReviewHeader({
review,
isRefreshing,
canUnlinkPullRequest,
showSystemBrowserHint,
onRefresh,
onOpenReview,
onUnlinkPullRequest,
@@ -183,6 +190,14 @@ export function ChecksPanelReviewHeader({
const ReviewIcon = review.provider === 'gitlab' ? GitMerge : PullRequestIcon
const reviewHostLabel = review.provider === 'gitlab' ? 'GitLab' : 'GitHub'
const showPullRequestMenu = review.provider === 'github'
const openTitle = translate(
'auto.components.right.sidebar.ChecksPanel.5c88c6db07',
'Open on {{value0}}',
{ value0: reviewHostLabel }
)
const title = showSystemBrowserHint
? `${openTitle}. ${getTerminalUrlSystemBrowserHint()}`
: openTitle
return (
<div className="flex items-center gap-2">
@@ -190,11 +205,7 @@ export function ChecksPanelReviewHeader({
<button
type="button"
className="rounded px-0.5 text-[12px] font-semibold text-foreground underline decoration-border underline-offset-2 hover:text-foreground hover:decoration-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
title={translate(
'auto.components.right.sidebar.ChecksPanel.5c88c6db07',
'Open on {{value0}}',
{ value0: reviewHostLabel }
)}
title={title}
onClick={onOpenReview}
>
{reviewNumberLabel}
@@ -2542,13 +2553,21 @@ export default function ChecksPanel(): React.JSX.Element {
)
// Open hosted review in browser
const handleOpenPR = useCallback(() => {
if (activeReview?.url) {
// Why: route through openHttpLink so PR/MR links honor the "open links
// in app" setting instead of always launching the system browser.
openHttpLink(activeReview.url, { worktreeId: activeWorktreeId })
}
}, [activeReview, activeWorktreeId])
const handleOpenPR = useCallback(
(event: React.MouseEvent<HTMLButtonElement>) => {
if (activeReview?.url) {
// Why: route through openHttpLink so PR/MR links honor the "open links
// in app" setting; Shift+Cmd/Ctrl keeps the terminal-link escape hatch.
openChecksPanelHostedReviewUrl({
url: activeReview.url,
event: event.nativeEvent,
isMac: isMacPlatform(),
worktreeId: activeWorktreeId
})
}
},
[activeReview, activeWorktreeId]
)
const handleUnlinkPullRequest = useCallback(() => {
if (!activeWorktreeId || activeReview?.provider !== 'github' || linkedPR === null) {
@@ -3068,6 +3087,12 @@ export default function ChecksPanel(): React.JSX.Element {
const reviewShortLabel = activeReview.provider === 'gitlab' ? 'MR' : 'PR'
const shouldShowReviewTriageStrip =
activeConflictReview !== null || getBrokenChecks(checks).length > 0
// Why: mirror openHttpLink's global routing inputs so the hint only appears
// when the actual plain-click path would open inside Orca.
const showHostedReviewSystemBrowserHint =
Boolean(activeWorktreeId) &&
settings?.openLinksInApp === true &&
!settings.activeRuntimeEnvironmentId
return (
<div ref={setChecksPanelContentRef} className="flex-1 overflow-auto scrollbar-sleek">
{/* Hosted review header */}
@@ -3077,6 +3102,7 @@ export default function ChecksPanel(): React.JSX.Element {
review={activeReview}
isRefreshing={isRefreshing}
canUnlinkPullRequest={linkedPR !== null}
showSystemBrowserHint={showHostedReviewSystemBrowserHint}
onRefresh={() => void handleRefresh()}
onOpenReview={handleOpenPR}
onUnlinkPullRequest={handleUnlinkPullRequest}
@@ -1,9 +1,16 @@
import React from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { HostedReviewInfo } from '../../../../shared/hosted-review'
import { HostedReviewHeaderLink } from './hosted-review-header-chrome'
const { openHttpLinkMock } = vi.hoisted(() => ({ openHttpLinkMock: vi.fn() }))
vi.mock('@/lib/http-link-routing', () => ({
openHttpLink: openHttpLinkMock,
registerHttpLinkStoreAccessor: vi.fn()
}))
function makeReview(overrides: Partial<HostedReviewInfo> = {}): HostedReviewInfo {
return {
provider: 'github',
@@ -18,7 +25,26 @@ function makeReview(overrides: Partial<HostedReviewInfo> = {}): HostedReviewInfo
}
}
type MinimalClickEvent = Pick<React.MouseEvent, 'stopPropagation'>
type MinimalClickEvent = Pick<
React.MouseEvent<HTMLButtonElement>,
'nativeEvent' | 'stopPropagation'
>
type ClickModifiers = Partial<Pick<MouseEvent, 'metaKey' | 'ctrlKey' | 'shiftKey'>>
function clickEvent(modifiers: ClickModifiers = {}): MinimalClickEvent {
return {
nativeEvent: {
metaKey: modifiers.metaKey ?? false,
ctrlKey: modifiers.ctrlKey ?? false,
shiftKey: modifiers.shiftKey ?? false
} as MouseEvent,
stopPropagation: vi.fn()
}
}
beforeEach(() => {
openHttpLinkMock.mockReset()
})
describe('HostedReviewHeaderLink', () => {
it('opens GitHub PRs in the Checks tab instead of rendering an external link', () => {
@@ -34,11 +60,34 @@ describe('HostedReviewHeaderLink', () => {
expect(markup).toContain('underline decoration-border underline-offset-2')
expect(markup).not.toContain('href=')
expect(markup).not.toContain('target="_blank"')
expect(markup).not.toContain('system browser')
expect(markup).not.toContain('⌘+click')
const stopPropagation = vi.fn()
;(element.props.onClick as (event: MinimalClickEvent) => void)({ stopPropagation })
expect(stopPropagation).toHaveBeenCalledTimes(1)
const event = clickEvent()
;(element.props.onClick as (event: MinimalClickEvent) => void)(event)
expect(event.stopPropagation).toHaveBeenCalledTimes(1)
expect(onOpenHostedReviewInChecks).toHaveBeenCalledTimes(1)
expect(openHttpLinkMock).not.toHaveBeenCalled()
})
it.each<[string, ClickModifiers]>([
['Cmd-click', { metaKey: true }],
['Ctrl-click', { ctrlKey: true }],
['Shift+Cmd-click', { metaKey: true, shiftKey: true }],
['Shift+Ctrl-click', { ctrlKey: true, shiftKey: true }]
])('opens GitHub PRs in the Checks tab on %s', (_label, modifiers) => {
const onOpenHostedReviewInChecks = vi.fn()
const element = HostedReviewHeaderLink({
review: makeReview(),
onOpenHostedReviewInChecks
})
const event = clickEvent(modifiers)
;(element.props.onClick as (event: MinimalClickEvent) => void)(event)
expect(event.stopPropagation).toHaveBeenCalledTimes(1)
expect(onOpenHostedReviewInChecks).toHaveBeenCalledTimes(1)
expect(openHttpLinkMock).not.toHaveBeenCalled()
})
it('opens GitLab MRs in the Checks tab instead of rendering an external link', () => {
@@ -57,10 +106,35 @@ describe('HostedReviewHeaderLink', () => {
expect(markup).not.toContain('href=')
expect(markup).toContain('MR #31')
const stopPropagation = vi.fn()
;(element.props.onClick as (event: MinimalClickEvent) => void)({ stopPropagation })
expect(stopPropagation).toHaveBeenCalledTimes(1)
const event = clickEvent()
;(element.props.onClick as (event: MinimalClickEvent) => void)(event)
expect(event.stopPropagation).toHaveBeenCalledTimes(1)
expect(onOpenHostedReviewInChecks).toHaveBeenCalledTimes(1)
expect(openHttpLinkMock).not.toHaveBeenCalled()
})
it.each<[string, ClickModifiers]>([
['Cmd-click', { metaKey: true }],
['Ctrl-click', { ctrlKey: true }],
['Shift+Cmd-click', { metaKey: true, shiftKey: true }],
['Shift+Ctrl-click', { ctrlKey: true, shiftKey: true }]
])('opens GitLab MRs in the Checks tab on %s', (_label, modifiers) => {
const onOpenHostedReviewInChecks = vi.fn()
const element = HostedReviewHeaderLink({
review: makeReview({
provider: 'gitlab',
number: 31,
url: 'https://gitlab.com/acme/widgets/-/merge_requests/31'
}),
onOpenHostedReviewInChecks
})
const event = clickEvent(modifiers)
;(element.props.onClick as (event: MinimalClickEvent) => void)(event)
expect(event.stopPropagation).toHaveBeenCalledTimes(1)
expect(onOpenHostedReviewInChecks).toHaveBeenCalledTimes(1)
expect(openHttpLinkMock).not.toHaveBeenCalled()
})
it('keeps other provider reviews as external hosted-review links', () => {
@@ -0,0 +1,75 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import {
isChecksPanelHostedReviewSystemBrowserModifier,
openChecksPanelHostedReviewUrl,
resolveChecksPanelHostedReviewHttpOpenOptions
} from './checks-panel-hosted-review-click-routing'
const { openHttpLinkMock } = vi.hoisted(() => ({ openHttpLinkMock: vi.fn() }))
vi.mock('@/lib/http-link-routing', () => ({
openHttpLink: openHttpLinkMock
}))
beforeEach(() => {
openHttpLinkMock.mockReset()
})
describe('checks panel hosted review click routing', () => {
it('maps Shift+Cmd to forceSystemBrowser on macOS', () => {
const event = { metaKey: true, ctrlKey: false, shiftKey: true }
expect(isChecksPanelHostedReviewSystemBrowserModifier(event, true)).toBe(true)
expect(resolveChecksPanelHostedReviewHttpOpenOptions(event, true, 'wt-1')).toEqual({
worktreeId: 'wt-1',
forceSystemBrowser: true
})
})
it('maps Shift+Ctrl to forceSystemBrowser off macOS', () => {
const event = { metaKey: false, ctrlKey: true, shiftKey: true }
expect(isChecksPanelHostedReviewSystemBrowserModifier(event, false)).toBe(true)
expect(resolveChecksPanelHostedReviewHttpOpenOptions(event, false, 'wt-1')).toEqual({
worktreeId: 'wt-1',
forceSystemBrowser: true
})
})
it('preserves the worktree id without forceSystemBrowser on plain clicks', () => {
expect(
resolveChecksPanelHostedReviewHttpOpenOptions(
{ metaKey: false, ctrlKey: false, shiftKey: false },
true,
'wt-1'
)
).toEqual({ worktreeId: 'wt-1' })
})
it('opens hosted review URLs without forceSystemBrowser on plain clicks', () => {
openChecksPanelHostedReviewUrl({
url: 'https://github.com/acme/widgets/pull/123',
event: { metaKey: false, ctrlKey: false, shiftKey: false },
isMac: true,
worktreeId: 'wt-1'
})
expect(openHttpLinkMock).toHaveBeenCalledWith('https://github.com/acme/widgets/pull/123', {
worktreeId: 'wt-1'
})
})
it('opens hosted review URLs with forceSystemBrowser on Shift+Cmd clicks', () => {
openChecksPanelHostedReviewUrl({
url: 'https://github.com/acme/widgets/pull/123',
event: { metaKey: true, ctrlKey: false, shiftKey: true },
isMac: true,
worktreeId: 'wt-1'
})
expect(openHttpLinkMock).toHaveBeenCalledWith('https://github.com/acme/widgets/pull/123', {
worktreeId: 'wt-1',
forceSystemBrowser: true
})
})
})
@@ -0,0 +1,35 @@
import { openHttpLink, type OpenHttpLinkOptions } from '@/lib/http-link-routing'
type ChecksPanelHostedReviewClickEvent = Pick<MouseEvent, 'metaKey' | 'ctrlKey' | 'shiftKey'>
export function isChecksPanelHostedReviewSystemBrowserModifier(
event: ChecksPanelHostedReviewClickEvent,
isMac: boolean
): boolean {
return event.shiftKey && (isMac ? event.metaKey : event.ctrlKey)
}
export function resolveChecksPanelHostedReviewHttpOpenOptions(
event: ChecksPanelHostedReviewClickEvent,
isMac: boolean,
worktreeId: string | null | undefined
): OpenHttpLinkOptions {
if (isChecksPanelHostedReviewSystemBrowserModifier(event, isMac)) {
return { worktreeId, forceSystemBrowser: true }
}
return { worktreeId }
}
export function openChecksPanelHostedReviewUrl({
url,
event,
isMac,
worktreeId
}: {
url: string
event: ChecksPanelHostedReviewClickEvent
isMac: boolean
worktreeId: string | null | undefined
}): void {
openHttpLink(url, resolveChecksPanelHostedReviewHttpOpenOptions(event, isMac, worktreeId))
}
@@ -26,6 +26,10 @@ export function getTerminalUrlOpenHint(): string {
: 'Ctrl+click to open or Shift+Ctrl+click for system browser'
}
export function getTerminalUrlSystemBrowserHint(): string {
return isMacPlatform() ? '⇧⌘+click for system browser' : 'Shift+Ctrl+click for system browser'
}
export function getTerminalWorktreePathOpenHint(canOpenWithSystemDefault: boolean): string {
if (!canOpenWithSystemDefault) {
return isMacPlatform() ? '⌘+click to switch workspace' : 'Ctrl+click to switch workspace'