mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
feat(cloud): GH-ACTING-LINE who pushes and PRs go out as, in source control and the people tooltip
A cloud workspace's git acts as its solo owner, else the latest sender within the hour, else Orca's bot; the control plane decides (#817's gitActor) and the desktop only says it, quietly: - Source control, under Commit/Push: "Pushes and PRs go out as @login" / "as Orca bot" / "as Orca bot (no one has sent in the last hour)", with the approvals/merges caveat in its tooltip. The only place with an action: Connect GitHub, when it's the bot and the viewer isn't connected. - The people chip: the same words as a second line in the acting member's avatar tooltip (the first avatar's when it's the bot). No new header chip. - Read with feature `git-actor` from GET /v1/team/workspaces/:id (owner and members alike), one read per workspace shared by both places; re-read on focus, every 2 min, and when a shared workspace's hour lapses (`until`). Absent field (not GitHub, identities off, older control plane): nothing shown.
This commit is contained in:
@@ -269,3 +269,30 @@ describe('cloud workspaces client: owner change (OWNER-TRANSFER)', () => {
|
||||
expect(init?.method).toBe('POST')
|
||||
})
|
||||
})
|
||||
|
||||
describe('cloud workspaces client: git actor (GH-ACTING-LINE)', () => {
|
||||
it('asks for feature git-actor on the detail read and parses the actor', async () => {
|
||||
const { client, fetch } = clientAnswering(200, {
|
||||
workspace: { id: SBX },
|
||||
gitActor: { kind: 'member', userId: 'u1', login: 'octo-dev', until: 123 },
|
||||
viewerConnected: true
|
||||
})
|
||||
expect(await client.gitActor(SBX)).toEqual({
|
||||
gitActor: { kind: 'member', userId: 'u1', login: 'octo-dev', until: 123 },
|
||||
viewerConnected: true
|
||||
})
|
||||
const [url, init] = fetch.mock.calls[0]!
|
||||
expect(String(url)).toBe(`https://cp.example.test/v1/team/workspaces/${SBX}`)
|
||||
expect(new Headers(init?.headers).get('x-orca-sandbox-features')).toBe('git-actor')
|
||||
})
|
||||
|
||||
it('an older control plane (no field) or an unknown shape reads as no actor', async () => {
|
||||
expect(await clientAnswering(200, { workspace: { id: SBX } }).client.gitActor(SBX)).toEqual({})
|
||||
expect(
|
||||
await clientAnswering(200, {
|
||||
gitActor: { kind: 'robot' },
|
||||
viewerConnected: 'yes'
|
||||
}).client.gitActor(SBX)
|
||||
).toEqual({})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
CloudWorkspaceListResponseSchema,
|
||||
CloudWorkspacePresenceResponseSchema,
|
||||
CloudWorkspaceResponseSchema,
|
||||
CloudWorkspaceGitActorSchema,
|
||||
CloudWorkspaceFollowSchema,
|
||||
OrgPromptsSchema,
|
||||
type CloudWorkspaceLinkTarget,
|
||||
@@ -78,7 +79,8 @@ export function createCloudWorkspacesClient(options: CloudWorkspacesClientOption
|
||||
schema: z.ZodType<T>,
|
||||
body?: unknown,
|
||||
timeoutMs = CONTROL_TIMEOUT_MS,
|
||||
maxBytes = MAX_RESPONSE_BYTES
|
||||
maxBytes = MAX_RESPONSE_BYTES,
|
||||
features?: string
|
||||
): Promise<T> {
|
||||
const signal = AbortSignal.timeout(timeoutMs)
|
||||
let token: string
|
||||
@@ -95,6 +97,7 @@ export function createCloudWorkspacesClient(options: CloudWorkspacesClientOption
|
||||
headers: {
|
||||
authorization: `Bearer ${token}`,
|
||||
accept: 'application/json',
|
||||
...(features ? { 'x-orca-sandbox-features': features } : {}),
|
||||
...(body === undefined ? {} : { 'content-type': 'application/json' })
|
||||
},
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
@@ -157,6 +160,11 @@ export function createCloudWorkspacesClient(options: CloudWorkspacesClientOption
|
||||
async get(id: string) {
|
||||
return (await call('GET', ws(id), CloudWorkspaceResponseSchema)).workspace
|
||||
},
|
||||
/** GH-ACTING-LINE: the detail read, asking for who git acts as. */
|
||||
async gitActor(id: string) {
|
||||
const read = CloudWorkspaceGitActorSchema
|
||||
return call('GET', ws(id), read, undefined, undefined, undefined, 'git-actor')
|
||||
},
|
||||
async patch(id: string, patch: CloudWorkspacePatch) {
|
||||
return call('PATCH', ws(id), CloudWorkspaceResponseSchema.extend({}).passthrough(), patch)
|
||||
},
|
||||
|
||||
@@ -213,6 +213,7 @@ export function createCloudWorkspacesService(deps: {
|
||||
return reader.read(id)
|
||||
}),
|
||||
get: (id: string) => wrap(() => client.get(id)),
|
||||
gitActor: (id: string) => wrap(() => client.gitActor(id)),
|
||||
follow: (id: string, follow: boolean) => wrap(() => client.follow(id, follow)),
|
||||
patch: (id: string, patch: CloudWorkspacePatch) =>
|
||||
wrap(async () => (await client.patch(id, patch)).workspace),
|
||||
|
||||
@@ -23,6 +23,12 @@ export function registerCloudWorkspacePrefsHandlers(
|
||||
? s.putPrefs(parsed.data.document, parsed.data.revision)
|
||||
: INVALID
|
||||
})
|
||||
// GH-ACTING-LINE: who the workspace's pushes and PRs go out as right now.
|
||||
handle('cloudWorkspaces:gitActor', async (args) => {
|
||||
const parsed = z.object({ id: z.string().regex(/^sbx_[0-9a-f]{24}$/) }).safeParse(args)
|
||||
const s = await getService()
|
||||
return !s ? NOT_CONFIGURED : parsed.success ? s.gitActor(parsed.data.id) : INVALID
|
||||
})
|
||||
handle('cloudWorkspaces:getOrgSlug', async (args) => {
|
||||
const parsed = z.object({ orgName: z.string().max(200).nullable().optional() }).safeParse(args)
|
||||
const s = await getService()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type {
|
||||
CloudWorkspace,
|
||||
CloudWorkspaceGitActor,
|
||||
CloudWorkspaceFollow,
|
||||
CloudWorkspaceGrant,
|
||||
CloudOrgSlug,
|
||||
@@ -41,6 +42,8 @@ export type CloudWorkspacesApi = {
|
||||
available: () => Promise<boolean>
|
||||
list: (query: CloudWorkspaceListQuery) => Promise<CloudWorkspaceListResult>
|
||||
get: (id: string) => Promise<CloudWorkspacesResult<CloudWorkspace>>
|
||||
/** GH-ACTING-LINE: who the workspace's pushes and PRs go out as right now. */
|
||||
gitActor?: (id: string) => Promise<CloudWorkspacesResult<CloudWorkspaceGitActor>>
|
||||
patch: (id: string, patch: CloudWorkspacePatch) => Promise<CloudWorkspacesResult<CloudWorkspace>>
|
||||
/** Follow or unfollow a team workspace (PARITY-FOLLOW): the caller's state and its followers. */
|
||||
follow: (id: string, follow: boolean) => Promise<CloudWorkspacesResult<CloudWorkspaceFollow>>
|
||||
|
||||
@@ -5,6 +5,7 @@ export const cloudWorkspacesApi = {
|
||||
available: () => ipcRenderer.invoke('cloudWorkspaces:available'),
|
||||
list: (query) => ipcRenderer.invoke('cloudWorkspaces:list', query),
|
||||
get: (id) => ipcRenderer.invoke('cloudWorkspaces:get', { id }),
|
||||
gitActor: (id) => ipcRenderer.invoke('cloudWorkspaces:gitActor', { id }),
|
||||
patch: (id, patch) => ipcRenderer.invoke('cloudWorkspaces:patch', { id, patch }),
|
||||
follow: (id, follow) => ipcRenderer.invoke('cloudWorkspaces:follow', { id, follow }),
|
||||
resolveLink: (target, chatId) =>
|
||||
|
||||
@@ -80,6 +80,7 @@ export function CloudWorkspaceFollowers({
|
||||
busy = false,
|
||||
onToggleFollow,
|
||||
onOpenMember,
|
||||
acting = null,
|
||||
max = 3
|
||||
}: {
|
||||
entries: WorkspaceFollowerEntry[]
|
||||
@@ -91,6 +92,11 @@ export function CloudWorkspaceFollowers({
|
||||
onToggleFollow?: () => void
|
||||
/** Opens the teammate's profile. */
|
||||
onOpenMember?: (userId: string) => void
|
||||
/**
|
||||
* GH-ACTING-LINE: who pushes and PRs go out as, said in the acting member's tooltip (or the first
|
||||
* avatar's when it's Orca's bot). Words only: no action here.
|
||||
*/
|
||||
acting?: { text: string; userId: string | null } | null
|
||||
max?: number
|
||||
}): React.JSX.Element | null {
|
||||
const t = useTranslate()
|
||||
@@ -107,7 +113,11 @@ export function CloudWorkspaceFollowers({
|
||||
aria-label={t('cloudFollow.stackLabel', 'People on this workspace')}
|
||||
className="flex items-center -space-x-1"
|
||||
>
|
||||
{shown.map((entry) => {
|
||||
{shown.map((entry, index) => {
|
||||
const actingHere =
|
||||
acting !== null &&
|
||||
(acting.userId === entry.userId ||
|
||||
(index === 0 && !shown.some((e) => e.userId === acting.userId)))
|
||||
const name = memberName(directory, entry.userId, selfId, t)
|
||||
const label = entryLabel(entry, name, t)
|
||||
const ring: React.CSSProperties & { '--avatar-hue': string } = {
|
||||
@@ -139,6 +149,7 @@ export function CloudWorkspaceFollowers({
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom" sideOffset={6}>
|
||||
{label}
|
||||
{actingHere ? <div className="text-muted-foreground">{acting.text}</div> : null}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
|
||||
@@ -13,6 +13,8 @@ import { CloudWorkspaceFollowers, workspaceFollowerEntries } from './CloudWorksp
|
||||
import { setCloudWorkspaceFollow, useTeamWorkspacesLive } from './team-workspaces-live'
|
||||
import { useMemberDirectory } from './use-cloud-workspace-row-actions'
|
||||
import { useCloudWorkspacesAvailable } from './use-cloud-workspaces'
|
||||
import { gitActingLine } from './cloud-git-acting-copy'
|
||||
import { useCloudGitActor } from './use-cloud-git-actor'
|
||||
|
||||
/**
|
||||
* Follow is offered on a teammate's team workspace; never on your own (it is yours already), and not
|
||||
@@ -44,6 +46,9 @@ export function CloudWorkspacePeople({
|
||||
const live = useTeamWorkspacesLive(orgId && available && sandboxId ? account : null)
|
||||
const workspace = sandboxId ? (live?.find((w) => w.id === sandboxId) ?? null) : null
|
||||
const { directory } = useMemberDirectory(orgId ?? undefined, workspace ? [workspace] : [])
|
||||
const gitActor = useCloudGitActor(workspace ? worktreeId : null)
|
||||
const actingLine = gitActingLine(gitActor, t)
|
||||
const actingUserId = gitActor?.gitActor?.kind === 'member' ? gitActor.gitActor.userId : null
|
||||
if (!workspace) {
|
||||
return null
|
||||
}
|
||||
@@ -80,6 +85,7 @@ export function CloudWorkspacePeople({
|
||||
busy={busy}
|
||||
onToggleFollow={toggle}
|
||||
onOpenMember={(userId) => (userId === selfId ? undefined : openTeammateProfile(userId))}
|
||||
acting={actingLine ? { text: actingLine.text, userId: actingUserId } : null}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// GH-ACTING-LINE: who a cloud workspace's pushes and PRs go out as right now, in words. The control
|
||||
// plane decides (the solo owner, else the latest sender within the hour, else Orca's bot) and says
|
||||
// so in `gitActor`; this only puts it into words. Nothing when the field is absent (not on GitHub,
|
||||
// member identities off, an older control plane).
|
||||
import type { Translate } from '@/i18n/use-translate'
|
||||
import type { CloudWorkspaceGitActor } from '../../../../shared/cloud-workspaces/cloud-workspaces-wire'
|
||||
|
||||
export type GitActingLine = {
|
||||
text: string
|
||||
/** The viewer could be the one it acts as, but hasn't connected GitHub: offer Connect GitHub. */
|
||||
connect: boolean
|
||||
}
|
||||
|
||||
export function gitActingLine(
|
||||
answer: CloudWorkspaceGitActor | null,
|
||||
t: Translate
|
||||
): GitActingLine | null {
|
||||
const actor = answer?.gitActor
|
||||
if (!actor) {
|
||||
return null
|
||||
}
|
||||
if (actor.kind === 'member') {
|
||||
return {
|
||||
text: t('cloudGitActing.member', 'Pushes and PRs go out as @{{login}}', {
|
||||
login: actor.login
|
||||
}),
|
||||
connect: false
|
||||
}
|
||||
}
|
||||
return {
|
||||
text:
|
||||
actor.reason === 'stale'
|
||||
? t(
|
||||
'cloudGitActing.stale',
|
||||
'Pushes and PRs go out as Orca bot (no one has sent in the last hour)'
|
||||
)
|
||||
: t('cloudGitActing.bot', 'Pushes and PRs go out as Orca bot'),
|
||||
connect: answer?.viewerConnected === false
|
||||
}
|
||||
}
|
||||
|
||||
/** The caveat that holds whatever the line says. */
|
||||
export function gitActingCaveat(t: Translate): string {
|
||||
return t(
|
||||
'cloudGitActing.caveat',
|
||||
'Approvals always go out as Orca bot, and so do merges in shared workspaces.'
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// GH-ACTING-LINE: one read per workspace, deduped; re-read when forced (the window lapsing).
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { refreshCloudGitActor } from './use-cloud-git-actor'
|
||||
|
||||
vi.mock('@/store', () => ({ useAppStore: () => null }))
|
||||
vi.mock('./cloud-workspace-identity', () => ({
|
||||
sandboxIdForWorktree: () => null,
|
||||
useCloudWorkspaceIdentities: () => null
|
||||
}))
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
describe('refreshCloudGitActor', () => {
|
||||
it('dedupes reads in flight and within the fresh window; a forced read goes through', async () => {
|
||||
const gitActor = vi.fn(async () => ({
|
||||
ok: true,
|
||||
value: { gitActor: { kind: 'bot', reason: 'stale' } }
|
||||
}))
|
||||
vi.stubGlobal('window', { api: { cloudWorkspaces: { gitActor } } })
|
||||
await Promise.all([refreshCloudGitActor('sbx_a'), refreshCloudGitActor('sbx_a')])
|
||||
await refreshCloudGitActor('sbx_a')
|
||||
expect(gitActor).toHaveBeenCalledTimes(1)
|
||||
await refreshCloudGitActor('sbx_a', true)
|
||||
expect(gitActor).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('an older desktop bridge without gitActor reads nothing', async () => {
|
||||
vi.stubGlobal('window', { api: { cloudWorkspaces: {} } })
|
||||
await expect(refreshCloudGitActor('sbx_b')).resolves.toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,82 @@
|
||||
// GH-ACTING-LINE: the git actor of the cloud workspace a worktree belongs to, shared by the people
|
||||
// tooltip and the source control panel (one read per workspace). Re-read when Orca is focused,
|
||||
// when a shared workspace's hour lapses (`until`), and every two minutes while mounted, since
|
||||
// another member sending also changes it.
|
||||
import { useEffect, useSyncExternalStore } from 'react'
|
||||
import { useAppStore } from '@/store'
|
||||
import type { CloudWorkspaceGitActor } from '../../../../shared/cloud-workspaces/cloud-workspaces-wire'
|
||||
import { sandboxIdForWorktree, useCloudWorkspaceIdentities } from './cloud-workspace-identity'
|
||||
|
||||
const REFRESH_MS = 2 * 60_000
|
||||
const FRESH_MS = 15_000
|
||||
|
||||
type Entry = { value: CloudWorkspaceGitActor | null; at: number; inflight: Promise<void> | null }
|
||||
const entries = new Map<string, Entry>()
|
||||
const listeners = new Set<() => void>()
|
||||
const emit = (): void => listeners.forEach((listener) => listener())
|
||||
|
||||
/** Reads the actor now (deduped while one is in flight, and not again within FRESH_MS unless forced). */
|
||||
export function refreshCloudGitActor(sandboxId: string, force = false): Promise<void> {
|
||||
const entry = entries.get(sandboxId) ?? { value: null, at: 0, inflight: null }
|
||||
entries.set(sandboxId, entry)
|
||||
if (entry.inflight || (!force && Date.now() - entry.at < FRESH_MS)) {
|
||||
return entry.inflight ?? Promise.resolve()
|
||||
}
|
||||
const read = window.api.cloudWorkspaces.gitActor
|
||||
if (!read) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
entry.inflight = read(sandboxId)
|
||||
.then((result) => {
|
||||
// A failed read keeps the last answer; the next focus or tick asks again.
|
||||
if (result.ok) {
|
||||
entry.value = result.value
|
||||
}
|
||||
})
|
||||
.catch(() => undefined)
|
||||
.finally(() => {
|
||||
entry.at = Date.now()
|
||||
entry.inflight = null
|
||||
emit()
|
||||
})
|
||||
return entry.inflight
|
||||
}
|
||||
|
||||
export function useCloudGitActor(worktreeId: string | null): CloudWorkspaceGitActor | null {
|
||||
const hostId = useAppStore((s) => s.activeWorkspaceExecutionHostId)
|
||||
const identities = useCloudWorkspaceIdentities()
|
||||
const sandboxId = worktreeId ? sandboxIdForWorktree({ id: worktreeId, hostId }, identities) : null
|
||||
const value = useSyncExternalStore(
|
||||
(listener) => {
|
||||
listeners.add(listener)
|
||||
return () => listeners.delete(listener)
|
||||
},
|
||||
() => (sandboxId ? (entries.get(sandboxId)?.value ?? null) : null)
|
||||
)
|
||||
const until = value?.gitActor?.kind === 'member' ? value.gitActor.until : undefined
|
||||
useEffect(() => {
|
||||
if (!sandboxId) {
|
||||
return
|
||||
}
|
||||
void refreshCloudGitActor(sandboxId)
|
||||
const onFocus = (): void => void refreshCloudGitActor(sandboxId)
|
||||
window.addEventListener('focus', onFocus)
|
||||
const tick = setInterval(() => void refreshCloudGitActor(sandboxId), REFRESH_MS)
|
||||
return () => {
|
||||
window.removeEventListener('focus', onFocus)
|
||||
clearInterval(tick)
|
||||
}
|
||||
}, [sandboxId])
|
||||
useEffect(() => {
|
||||
if (!sandboxId || until === undefined) {
|
||||
return
|
||||
}
|
||||
// A second past the window, so the server already answers with the bot.
|
||||
const timer = setTimeout(
|
||||
() => void refreshCloudGitActor(sandboxId, true),
|
||||
Math.max(0, until - Date.now()) + 1_000
|
||||
)
|
||||
return () => clearTimeout(timer)
|
||||
}, [sandboxId, until])
|
||||
return value
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// GH-ACTING-LINE under Commit/Push in a cloud workspace's source control panel.
|
||||
import { defineFixture } from '../../../../component-fixtures/component-fixture'
|
||||
import type { CloudWorkspaceGitActor } from '../../../../../../shared/cloud-workspaces/cloud-workspaces-wire'
|
||||
import { CloudGitActingNoticeView } from './cloud-git-acting-notice'
|
||||
|
||||
function fixture(answer: CloudWorkspaceGitActor) {
|
||||
return defineFixture({
|
||||
width: 320,
|
||||
render: () => (
|
||||
<div className="bg-background p-3">
|
||||
<div className="flex h-7 items-center justify-center rounded-md bg-primary text-xs text-primary-foreground">
|
||||
Commit & Push
|
||||
</div>
|
||||
<CloudGitActingNoticeView answer={answer} onConnect={() => {}} />
|
||||
</div>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export const member = fixture({
|
||||
gitActor: { kind: 'member', userId: 'u1', login: 'octo-dev' },
|
||||
viewerConnected: true
|
||||
})
|
||||
export const botConnect = fixture({
|
||||
gitActor: { kind: 'bot', reason: 'no_connected_member' },
|
||||
viewerConnected: false
|
||||
})
|
||||
export const botStale = fixture({
|
||||
gitActor: { kind: 'bot', reason: 'stale' },
|
||||
viewerConnected: true
|
||||
})
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
// @vitest-environment happy-dom
|
||||
// GH-ACTING-LINE: the source control panel says who pushes and PRs go out as, and offers Connect
|
||||
// GitHub only when it falls back to Orca's bot for a viewer who hasn't connected.
|
||||
import { act } from 'react'
|
||||
import { createRoot, type Root } from 'react-dom/client'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { TooltipProvider } from '@/components/ui/tooltip'
|
||||
import type { CloudWorkspaceGitActor } from '../../../../../../shared/cloud-workspaces/cloud-workspaces-wire'
|
||||
import { CloudGitActingNoticeView } from './cloud-git-acting-notice'
|
||||
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
let root: Root | null = null
|
||||
|
||||
afterEach(async () => {
|
||||
await act(async () => root?.unmount())
|
||||
root = null
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
|
||||
async function show(
|
||||
answer: CloudWorkspaceGitActor | null,
|
||||
onConnect = vi.fn()
|
||||
): Promise<HTMLElement> {
|
||||
const container = document.createElement('div')
|
||||
document.body.appendChild(container)
|
||||
root = createRoot(container)
|
||||
await act(async () =>
|
||||
root!.render(
|
||||
<TooltipProvider>
|
||||
<CloudGitActingNoticeView answer={answer} onConnect={onConnect} />
|
||||
</TooltipProvider>
|
||||
)
|
||||
)
|
||||
return container
|
||||
}
|
||||
|
||||
const connectButton = (c: HTMLElement) =>
|
||||
[...c.querySelectorAll('button')].find((b) => b.textContent === 'Connect GitHub') ?? null
|
||||
|
||||
describe('who pushes and PRs go out as, in source control', () => {
|
||||
it('a member: as @login, no action', async () => {
|
||||
const c = await show({
|
||||
gitActor: { kind: 'member', userId: 'u1', login: 'octo-dev' },
|
||||
viewerConnected: true
|
||||
})
|
||||
expect(c.textContent).toContain('Pushes and PRs go out as @octo-dev')
|
||||
expect(connectButton(c)).toBeNull()
|
||||
})
|
||||
|
||||
it('the bot for a viewer who isn’t connected: Connect GitHub', async () => {
|
||||
const onConnect = vi.fn()
|
||||
const c = await show(
|
||||
{ gitActor: { kind: 'bot', reason: 'no_connected_member' }, viewerConnected: false },
|
||||
onConnect
|
||||
)
|
||||
expect(c.textContent).toContain('Pushes and PRs go out as Orca bot')
|
||||
await act(async () => connectButton(c)!.click())
|
||||
expect(onConnect).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('the bot after the hour lapsed, viewer connected: says why, no action', async () => {
|
||||
const c = await show({ gitActor: { kind: 'bot', reason: 'stale' }, viewerConnected: true })
|
||||
expect(c.textContent).toContain('no one has sent in the last hour')
|
||||
expect(connectButton(c)).toBeNull()
|
||||
})
|
||||
|
||||
it('no actor (not GitHub, identities off, older control plane): nothing', async () => {
|
||||
expect((await show({ viewerConnected: false })).textContent).toBe('')
|
||||
expect((await show(null)).textContent).toBe('')
|
||||
})
|
||||
})
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
import React from 'react'
|
||||
import { Github } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { gitActingCaveat, gitActingLine } from '@/components/cloud-workspaces/cloud-git-acting-copy'
|
||||
import { useCloudGitActor } from '@/components/cloud-workspaces/use-cloud-git-actor'
|
||||
import type { CloudWorkspaceGitActor } from '../../../../../../shared/cloud-workspaces/cloud-workspaces-wire'
|
||||
|
||||
/**
|
||||
* GH-ACTING-LINE under Commit/Push in a cloud workspace: who pushes and PRs go out as right now, and,
|
||||
* when it falls back to Orca's bot for a viewer who hasn't connected GitHub, Connect GitHub. The
|
||||
* only place that action shows; the people tooltip just says who.
|
||||
*/
|
||||
export function CloudGitActingNoticeView({
|
||||
answer,
|
||||
onConnect
|
||||
}: {
|
||||
answer: CloudWorkspaceGitActor | null
|
||||
onConnect: () => void
|
||||
}): React.JSX.Element | null {
|
||||
const t = useTranslate()
|
||||
const line = gitActingLine(answer, t)
|
||||
if (!line) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<div
|
||||
data-cloud-git-acting
|
||||
className="mt-1.5 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5 text-2xs text-muted-foreground"
|
||||
>
|
||||
<Github aria-hidden className="size-3 shrink-0" />
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<span
|
||||
tabIndex={0}
|
||||
className="min-w-0 flex-1 outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
||||
>
|
||||
{line.text}
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" className="max-w-72">
|
||||
{gitActingCaveat(t)}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
{line.connect ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="link"
|
||||
size="statusAction"
|
||||
className="shrink-0"
|
||||
onClick={onConnect}
|
||||
>
|
||||
{t('cloudGitActing.connect', 'Connect GitHub')}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function CloudGitActingNotice({
|
||||
worktreeId
|
||||
}: {
|
||||
worktreeId: string | null
|
||||
}): React.JSX.Element | null {
|
||||
const answer = useCloudGitActor(worktreeId)
|
||||
// The browser OAuth finishes elsewhere; the actor is re-read when Orca is focused again.
|
||||
const connect = (): void =>
|
||||
void Promise.resolve()
|
||||
.then(() => window.api.orcaCloudWorkspace.connectGitHubUser())
|
||||
.catch(() => null)
|
||||
return <CloudGitActingNoticeView answer={answer} onConnect={connect} />
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import { CommitActionMenu } from './commit-action-menu'
|
||||
import type { CommitAreaProps } from './commit-area-types'
|
||||
import { CommitMessageComposer } from './commit-message-composer'
|
||||
import { CommitNotices } from './commit-notices'
|
||||
import { CloudGitActingNotice } from './cloud-git-acting-notice'
|
||||
import { getCommitMessageTextareaRows } from './commit-message-rows'
|
||||
import type { PrimaryAction } from '../review/source-control-primary-action-types'
|
||||
import { getSourceControlRecoveryFailureKindLabel } from '../sync/push-recovery'
|
||||
@@ -243,6 +244,7 @@ export function CommitArea({
|
||||
dropdownMenuContent={dropdownMenuContent}
|
||||
onPrimaryAction={onPrimaryAction}
|
||||
/>
|
||||
<CloudGitActingNotice worktreeId={worktreeId} />
|
||||
<CommitNotices
|
||||
worktreeId={worktreeId}
|
||||
groupId={groupId}
|
||||
|
||||
@@ -29311,6 +29311,13 @@
|
||||
"linkCopied": "Link copied",
|
||||
"signInLinkHint": "Open it in any browser on this computer."
|
||||
},
|
||||
"cloudGitActing": {
|
||||
"member": "Pushes and PRs go out as @{{login}}",
|
||||
"bot": "Pushes and PRs go out as Orca bot",
|
||||
"stale": "Pushes and PRs go out as Orca bot (no one has sent in the last hour)",
|
||||
"caveat": "Approvals always go out as Orca bot, and so do merges in shared workspaces.",
|
||||
"connect": "Connect GitHub"
|
||||
},
|
||||
"cloudFollow": {
|
||||
"role": {
|
||||
"creator": "Created this workspace",
|
||||
|
||||
@@ -91,6 +91,29 @@ export const CloudWorkspaceListResponseSchema = z.object({
|
||||
routineRuns: CloudWorkspaceRoutineRunsSchema.optional().catch(undefined)
|
||||
})
|
||||
export const CloudWorkspaceResponseSchema = z.object({ workspace: CloudWorkspaceSchema })
|
||||
/**
|
||||
* GH-ACTING-LINE: who the workspace's pushes and PRs go out as right now (the solo owner, else the
|
||||
* latest sender within the hour, else Orca's bot), on GET /v1/team/workspaces/:id with feature
|
||||
* `git-actor`. Absent: not on GitHub, or member identities off. `viewerConnected`: whether the
|
||||
* caller has a usable GitHub connection. `until`: when a shared workspace's window lapses.
|
||||
*/
|
||||
export const CloudGitActorSchema = z.discriminatedUnion('kind', [
|
||||
z.object({
|
||||
kind: z.literal('member'),
|
||||
userId: z.string().max(200),
|
||||
login: z.string().min(1).max(100),
|
||||
until: z.number().optional()
|
||||
}),
|
||||
z.object({ kind: z.literal('bot'), reason: z.string().max(60) })
|
||||
])
|
||||
export type CloudGitActor = z.infer<typeof CloudGitActorSchema>
|
||||
export const CloudWorkspaceGitActorSchema = z
|
||||
.object({
|
||||
gitActor: CloudGitActorSchema.optional().catch(undefined),
|
||||
viewerConnected: z.boolean().optional().catch(undefined)
|
||||
})
|
||||
.strip()
|
||||
export type CloudWorkspaceGitActor = z.infer<typeof CloudWorkspaceGitActorSchema>
|
||||
/** PUT/DELETE /v1/team/workspaces/:id/follow (PARITY-FOLLOW). */
|
||||
export const CloudWorkspaceFollowSchema = z.object({
|
||||
following: z.boolean(),
|
||||
|
||||
Reference in New Issue
Block a user