mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 18:47:40 +00:00
* [comment audit] Shorten daemon, hook, and emulator comments [skip ci] * [comment audit] Shorten VM, conversation, SQLite, and theme-import comments [skip ci] * [comment audit] Tighten Git execution and source-control comment contracts [skip ci] * [comment audit] Clarify repository probes and maintenance comments [skip ci] * [comment audit] Shorten status, diff-cache, and checkout comments [skip ci] * [comment audit] Clarify worktree lifecycle and WSL routing comments [skip ci] * [comment audit] Shorten forge identity and review-refresh comments [skip ci] * [comment audit] Tighten hosted-review client comment contracts [skip ci] * [comment audit] Clarify GitLab compatibility and review comments [skip ci] * [comment audit] Tighten hook ownership and watchdog rationale [skip ci] * [comment audit] Condense host and integration compatibility comments [skip ci] * [comment audit] Clarify IPC authority and remote-routing rationale [skip ci] * [comment audit] Finalize file-import and containment comment cleanup * [comment audit] Fix stale Jira type imports blocking full CI --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
110 lines
3.0 KiB
TypeScript
110 lines
3.0 KiB
TypeScript
import type { IssueSourcePreference } from '../../shared/repo-types'
|
|
import { githubRepoIdentityKey } from '../../shared/github/repository-identity-key'
|
|
import { shouldProbeGitRemote } from '../git/remote-name-listing'
|
|
import {
|
|
getOwnerRepoForRemote,
|
|
type LocalGitExecOptions,
|
|
type OwnerRepo
|
|
} from './github-repository-identity'
|
|
|
|
export async function getOwnerRepo(
|
|
repoPath: string,
|
|
connectionId?: string | null,
|
|
localGitOptions: LocalGitExecOptions = {}
|
|
): Promise<OwnerRepo | null> {
|
|
// Fork contribution PRs usually live on upstream.
|
|
const originPromise = getOwnerRepoForRemote(repoPath, 'origin', connectionId, localGitOptions)
|
|
if (await shouldProbeGitRemote(repoPath, 'upstream', connectionId, localGitOptions)) {
|
|
const upstream = await getOwnerRepoForRemote(
|
|
repoPath,
|
|
'upstream',
|
|
connectionId,
|
|
localGitOptions
|
|
)
|
|
if (upstream) {
|
|
return upstream
|
|
}
|
|
}
|
|
return originPromise
|
|
}
|
|
|
|
export const getIssueOwnerRepo = getOwnerRepo
|
|
|
|
export type PRRepositoryCandidates = {
|
|
candidates: OwnerRepo[]
|
|
headRepo: OwnerRepo | null
|
|
}
|
|
|
|
export async function resolvePRRepositoryCandidates(
|
|
repoPath: string,
|
|
connectionId?: string | null,
|
|
localGitOptions: LocalGitExecOptions = {}
|
|
): Promise<PRRepositoryCandidates> {
|
|
const originPromise = getOwnerRepoForRemote(repoPath, 'origin', connectionId, localGitOptions)
|
|
const probeUpstream = await shouldProbeGitRemote(
|
|
repoPath,
|
|
'upstream',
|
|
connectionId,
|
|
localGitOptions
|
|
)
|
|
const [upstream, origin] = await Promise.all([
|
|
probeUpstream
|
|
? getOwnerRepoForRemote(repoPath, 'upstream', connectionId, localGitOptions)
|
|
: null,
|
|
originPromise
|
|
])
|
|
const seen = new Set<string>()
|
|
const candidates: OwnerRepo[] = []
|
|
|
|
for (const candidate of [upstream, origin]) {
|
|
if (!candidate) {
|
|
continue
|
|
}
|
|
const key = githubRepoIdentityKey(candidate)
|
|
if (seen.has(key)) {
|
|
continue
|
|
}
|
|
seen.add(key)
|
|
candidates.push(candidate)
|
|
}
|
|
|
|
return { candidates, headRepo: origin }
|
|
}
|
|
|
|
export type ResolvedIssueSource = {
|
|
source: OwnerRepo | null
|
|
/** True when explicit upstream is gone and resolver fell back to origin. */
|
|
fellBack: boolean
|
|
}
|
|
|
|
export async function resolveIssueSource(
|
|
repoPath: string,
|
|
preference: IssueSourcePreference | undefined,
|
|
connectionId?: string | null,
|
|
localGitOptions: LocalGitExecOptions = {}
|
|
): Promise<ResolvedIssueSource> {
|
|
if (preference === 'upstream') {
|
|
const upstream = await getOwnerRepoForRemote(
|
|
repoPath,
|
|
'upstream',
|
|
connectionId,
|
|
localGitOptions
|
|
)
|
|
if (upstream) {
|
|
return { source: upstream, fellBack: false }
|
|
}
|
|
const origin = await getOwnerRepoForRemote(repoPath, 'origin', connectionId, localGitOptions)
|
|
return { source: origin, fellBack: origin !== null }
|
|
}
|
|
if (preference === 'origin') {
|
|
return {
|
|
source: await getOwnerRepoForRemote(repoPath, 'origin', connectionId, localGitOptions),
|
|
fellBack: false
|
|
}
|
|
}
|
|
return {
|
|
source: await getIssueOwnerRepo(repoPath, connectionId, localGitOptions),
|
|
fellBack: false
|
|
}
|
|
}
|