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

+50
View File
@@ -0,0 +1,50 @@
export class ManagerApi {
constructor(
private baseUrl: string,
private token: string,
) {}
private headers(extra: Record<string, string> = {}): Record<string, string> {
return { Authorization: `Bearer ${this.token}`, ...extra }
}
async mirrorUp(
repoId: number,
body: ReadableStream<Uint8Array>,
opts: { force?: boolean; create?: { name: string; originUrl: string | null; branch: string | null } },
): Promise<{ repoId: number; branch: string; head: string; created: boolean }> {
const params = new URLSearchParams()
if (opts.force) params.set('force', '1')
if (opts.create) {
params.set('create', '1')
params.set('name', opts.create.name)
if (opts.create.originUrl) params.set('originUrl', opts.create.originUrl)
if (opts.create.branch) params.set('branch', opts.create.branch)
}
const qs = params.toString() ? `?${params.toString()}` : ''
const url = `${this.baseUrl}/api/internal/repos/${repoId}/mirror${qs}`
const res = await fetch(url, {
method: 'POST',
headers: {
...this.headers(),
'Content-Type': 'application/x-tar',
},
body,
duplex: 'half',
} as RequestInit & { duplex: 'half' })
if (!res.ok) throw new Error(`mirror ${res.status}: ${await res.text()}`)
return (await res.json()) as { repoId: number; branch: string; head: string; created: boolean }
}
async mirrorDown(repoId: number): Promise<ReadableStream<Uint8Array>> {
const res = await fetch(`${this.baseUrl}/api/internal/repos/${repoId}/mirror`, {
headers: this.headers(),
})
if (!res.ok) throw new Error(`mirror ${res.status}: ${await res.text()}`)
return res.body!
}
}