diff --git a/CHANGELOG.md b/CHANGELOG.md index 8812ee4..069108c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.6.18 + +- `gild clone` imports a repository that was too large for gild's servers on your machine first, then clones it. + ## 0.6.17 - `gild setup` sets up gild 0.7.11: imported repositories no longer stay Pending (annotated tags and import refs blocked publishing). diff --git a/package.json b/package.json index 4f07294..967c27b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gild", - "version": "0.6.17", + "version": "0.6.18", "private": true, "type": "module", "bin": { diff --git a/src/api/import-contract.ts b/src/api/import-contract.ts index e3bc765..eaab988 100644 --- a/src/api/import-contract.ts +++ b/src/api/import-contract.ts @@ -16,7 +16,7 @@ export type ImportRecord = z.infer export const importInput = z.object({ url:z.string().min(1).max(2048), name:z.string().regex(/^[a-z0-9][a-z0-9._-]{0,62}$/i).optional(), private:z.boolean().optional(), mirror:z.boolean().default(false), source_token:z.string().max(16384).optional(), forge:z.enum(['github','gitlab','git']).optional() }) export const importProgress = z.object({ phase:z.enum(['git','metadata','workflows']), completed:z.number().int().nonnegative(), message:z.string().max(200), checkpoint:z.string().max(2048).optional(),default_branch:z.string().max(300).optional(),internal_prefix:z.string().regex(/^import_*\/pr$/).optional() }) export const importSummary=z.object({branches:z.number().int().nonnegative(),tags:z.number().int().nonnegative(),commits:z.number().int().nonnegative(),records:z.number().int().nonnegative(),elapsed_ms:z.number().nonnegative()}) -export const importStatus = z.object({ repository:z.string(), source:z.string(), mirror:z.boolean(), state:z.enum(['queued','running','complete','mirroring','failed','cutover']), progress:importProgress, warnings:z.array(z.string()), error:z.string().nullable(), updated_at:z.string(), next_sync:z.string().nullable(),summary:importSummary.optional() }) +export const importStatus = z.object({ repository:z.string(), source:z.string(), mirror:z.boolean(), state:z.enum(['queued','running','complete','mirroring','failed','cutover']), progress:importProgress, warnings:z.array(z.string()), error:z.string().nullable(), updated_at:z.string(), next_sync:z.string().nullable(),summary:importSummary.optional(),/** Too large for gild's servers: `gild clone` imports it locally. */local:z.boolean().optional() }) export const importAssignment = z.object({ repository:z.string(), source:z.string(), forge:z.enum(['github','gitlab','git']), token:z.string(), source_token:z.string().optional(), mirror:z.boolean(), checkpoint:z.string() }) export const importCredentials = z.object({ url:z.string(), token:z.string() }) export const importBatch = z.object({ records:z.array(importRecord).max(40), progress:importProgress }) diff --git a/src/gild-main.ts b/src/gild-main.ts index e649dfd..2c49b4d 100644 --- a/src/gild-main.ts +++ b/src/gild-main.ts @@ -1,5 +1,5 @@ #!/usr/bin/env bun -import { importCommands } from './import/commands' +import { importCommands, importIfWaiting } from './import/commands' import { ApiRequestError, GildClient } from './api/client' import { ProofClient } from './api/bootstrap-contract' import { serverTokenSchema, forgeServer, tokenForServer } from './server-token' @@ -622,6 +622,13 @@ const cloneAction = async ( ? agentServer(agent, opts.server) : forgeServer(opts.server ?? 'https://gild.gg') if (identity?.apiToken) tokenForServer(identity.apiToken, server) + if (identity && !agent) + await importIfWaiting( + await clientFor(server, identity), + server, + repoArg, + configDir(), + ) const helper = '!' + [ diff --git a/src/import/commands.ts b/src/import/commands.ts index 63737cd..cfc0cdd 100644 --- a/src/import/commands.ts +++ b/src/import/commands.ts @@ -6,6 +6,35 @@ import { homedir } from 'node:os' import type { GildClient } from '../api/client' import { sourceURL } from './source' import { executeImport } from './execute' +/** An import too large for gild's servers waits for its owner's machine: + * `gild clone` runs it here first, then clones as usual. */ +export async function importIfWaiting( + api: GildClient, + server: string, + repository: string, + root: string, +) { + const [owner, repo] = repository.split('/'), + params = { owner, repo } + const status = await api.request('importStatus', params).catch(() => null) + if (!status?.local || status.state !== 'queued') return + const job = await api.request('importClaim', params) + if (!job) return + console.log( + `Importing ${status.source} on this machine (too large for gild's servers)`, + ) + const controller = new AbortController(), + stop = () => controller.abort() + process.once('SIGINT', stop) + process.once('SIGTERM', stop) + try { + await executeImport(server, job, root, controller.signal) + } finally { + process.removeListener('SIGINT', stop) + process.removeListener('SIGTERM', stop) + } +} + export function importCommands( repo: Command, client: (server: string) => Promise,