Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gild",
"version": "0.6.17",
"version": "0.6.18",
"private": true,
"type": "module",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/import-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type ImportRecord = z.infer<typeof importRecord>
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 })
9 changes: 8 additions & 1 deletion src/gild-main.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 =
'!' +
[
Expand Down
29 changes: 29 additions & 0 deletions src/import/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GildClient>,
Expand Down
Loading