Files
orca/src/shared/github/work-item-target.ts
T
Brennan Benson 40f9d2a246 Keep desktop fork pull requests on their opened repository (#36172)
* Keep opened GitHub work items bound to their exact repository

* Bind GitHub work item ownership through consumers and dispatch

* Keep empty mention lists from consuming selection keys

* Preserve GitHub action and consumer ownership across resource changes

* Exercise repository account updates through their production store action

* Exercise account publication and cache settlement through GitHub consumers

* Simplify fork PR contract verification

* Make contract verification imports and clocks deterministic

* Correct mobile task test fixtures and model types

* Correct task recording fixtures and CI types

* Correct task fixture types and static checks

* Consolidate replay test RPC imports

* Separate GitHub metadata imports from Linear hooks

* Scope mobile PR sidebar reads to the selected resource

* Separate desktop GitHub changes from phone updates

* Fix relay authority probe census across topology cases

* Repair repository owner proof fixtures and compiler allocation

* Preserve repository row observation in host lookup

* Seed metadata fixture before server-side store acquisition

* Preserve nullable fixture settings and discover mixed test types

* Preserve GitHub detail argument types and optional capabilities

* Let keyed details queries own pending read replacement

* Repair GitHub RPC and relay test fixture boundaries

* Verify expected GitHub account at repository execution capture

* Preserve captured GitHub account expectations through client dispatch

* Retain observed runtime status after switching environments

* Fix account contract fixture types and RPC setup timing

* Restore the negative-capability switch probe assertion

* Align account fixtures with runtime identity and configured origin

* Consolidate details test imports

* Drop duplicate fork pull request identity tests
2026-11-02 13:22:48 -08:00

84 lines
2.8 KiB
TypeScript

import type { GitHubOwnerRepo } from './pull-request-types'
import type { GitHubWorkItem, GitHubWorkItemDetails } from './work-item-types'
import { githubRepoIdentityKey } from './repository-identity-key'
export type GitHubWorkItemTarget = {
repository: GitHubOwnerRepo
type: 'issue' | 'pr'
number: number
}
export function matchesGitHubWorkItemTarget(
item: Pick<GitHubWorkItem, 'url' | 'prRepo' | 'type' | 'number'> | null | undefined,
target: GitHubWorkItemTarget
): boolean {
if (!item || item.type !== target.type || item.number !== target.number) {
return false
}
try {
const url = new URL(item.url)
const parts = url.pathname.split('/').filter(Boolean)
if (
!['http:', 'https:'].includes(url.protocol) ||
parts.length !== 4 ||
parts[2] !== (target.type === 'pr' ? 'pull' : 'issues') ||
parts[3] !== String(target.number)
) {
return false
}
const repository = { host: url.host, owner: parts[0], repo: parts[1] }
const key = githubRepoIdentityKey(repository)
return (
key === githubRepoIdentityKey(target.repository) &&
(!item.prRepo || githubRepoIdentityKey(item.prRepo) === key)
)
} catch {
return false
}
}
export class GitHubWorkItemTargetError extends Error {
constructor(target: GitHubWorkItemTarget) {
const { owner, repo } = target.repository
super(
`Couldn't load ${owner}/${repo}#${target.number} from this server. Try again or open the ${target.type === 'pr' ? 'pull request' : 'issue'} on GitHub.`
)
}
}
export function requireGitHubWorkItemTargetDetails(
details: GitHubWorkItemDetails | null,
target: GitHubWorkItemTarget
): GitHubWorkItemDetails {
if (!details || !matchesGitHubWorkItemTarget(details.item, target)) {
throw new GitHubWorkItemTargetError(target)
}
return details
}
export const GITHUB_EXACT_OPERATION_UNSUPPORTED =
'Update Orca on the executing server to edit this item or load its repository options.'
export function githubWorkItemTargetKey(target: GitHubWorkItemTarget): string {
return [githubRepoIdentityKey(target.repository), target.type, target.number].join('\0')
}
export function parseGitHubItemRepository(url: string): GitHubOwnerRepo | null {
try {
const parsed = new URL(url)
const parts = parsed.pathname.split('/').filter(Boolean)
return ['https:', 'http:'].includes(parsed.protocol) && parts.length >= 2
? { host: parsed.host, owner: parts[0], repo: parts[1] }
: null
} catch {
return null
}
}
export function resolveGitHubWorkItemTarget(
item: Pick<GitHubWorkItem, 'url' | 'prRepo' | 'type' | 'number'>
): GitHubWorkItemTarget | null {
const repository = item.prRepo ?? parseGitHubItemRepository(item.url)
return repository ? { repository, type: item.type, number: item.number } : null
}