feat(ocm-cli): workspace repo sync and manager token targeting (#233)

This commit is contained in:
Chris Scott authored and GitHub committed 2026-05-23 19:49:44 -04:00
1 parent e12f319592
commit a86e4b1238
69 files changed
+4858 -161

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
import { getRepoRoot, getOriginUrl, urlsEqual } from './local-repo.js'
export interface TargetRepo {
repoId: number
name: string
branch: string | null
directory: string
originUrl?: string | null
}
export type ResolveResult =
| { kind: 'cwd-match'; repo: TargetRepo; repoRoot: string }
| { kind: 'last'; repo: TargetRepo }
| { kind: 'cwd-ambiguous'; matches: TargetRepo[]; localOrigin: string; repoRoot: string }
| { kind: 'local'; reason: 'no-match' | 'no-target'; repoRoot: string | null }
export interface ResolveInput {
cwd: string
repos: TargetRepo[]
last?: { repoId: number; name: string; directory: string; branch: string | null }
}
export function resolveTarget(input: ResolveInput): ResolveResult {
const repoRoot = getRepoRoot(input.cwd)
const localOrigin = repoRoot ? getOriginUrl(repoRoot) : null
if (repoRoot && localOrigin) {
const matches = input.repos.filter((r) => urlsEqual(localOrigin, r.originUrl))
if (matches.length === 1) {
return { kind: 'cwd-match', repo: matches[0]!, repoRoot }
}
if (matches.length > 1) {
return { kind: 'cwd-ambiguous', matches, localOrigin, repoRoot }
}
return { kind: 'local', reason: 'no-match', repoRoot }
}
if (input.last) {
return { kind: 'last', repo: toTarget(input.last) }
}
return { kind: 'local', reason: 'no-target', repoRoot }
}
function toTarget(last: NonNullable<ResolveInput['last']>): TargetRepo {
return {
repoId: last.repoId,
name: last.name,
branch: last.branch,
directory: last.directory,
}
}