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: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gildforge/kit",
"version": "0.7.11",
"version": "0.7.12",
"description": "The shared engine, views and server behind gild: the git forge for agents on Cloudflare.",
"license": "Apache-2.0",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/engine/api/import-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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 })
4 changes: 4 additions & 0 deletions src/server/api/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export async function apiImports(c:Context):Promise<Result> {
if(b.source_token && new URL(source.url).protocol==='http:') throw new ApiError(422,'Use HTTPS or SSH with a source token')
// Validate encryption before provisioning anything. Plaintext never enters durable storage.
if(b.source_token) await encrypt(env as {ACTIONS_SECRET_KEY?:string},`import:${owner}/${name}`,b.source_token)
// The same source already waiting for a local run (too large for the
// container): `gild repo import` picks that job up instead of failing.
const prior=await (async()=>{try {return await (await importJob(owner,name)).status()} catch {return null}})()
if(prior?.state==='queued' && prior.source===source.url) return {data:prior}
const isPrivate=destinationPrivate(b)
await createRepository(c.principal.name,owner,name,undefined,isPrivate,false)
const job=await importJob(owner,name)
Expand Down
2 changes: 1 addition & 1 deletion src/server/import/dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('a large GitHub source is measured from its API size in kilobytes', async (
assert.ok(bytes!>SERVER_IMPORT_LIMIT)
assert.equal(seen[0].url,'https://api.github.com/repos/torvalds/linux')
assert.equal(seen[0].headers.authorization,'Bearer t0k')
assert.match(tooLargeMessage(bytes!,'sami/linux'),/4\.8 GB.*gild repo resume sami\/linux/)
assert.match(tooLargeMessage(bytes!,'sami/linux'),/4\.8 GB.*gild clone sami\/linux$/)
})
test('GitLab statistics are bytes; plain git and failures are unknown', async () => {
assert.equal(await sourceBytes('https://gitlab.com/a/b',undefined,undefined,answer({statistics:{repository_size:42}})),42)
Expand Down
2 changes: 1 addition & 1 deletion src/server/import/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function sourceBytes(url:string,forge?:Forge,token?:string,fetcher:
} catch {return null}
}
export function tooLargeMessage(bytes:number,repository:string) {
return `Too large to import on gild's servers (${(bytes/1024**3).toFixed(1)} GB). Import it from your machine: gild repo resume ${repository}`
return `Too large to import on gild's servers (${(bytes/1024**3).toFixed(1)} GB). Import it from your machine: gild clone ${repository}`
}
/** gild-import (services/import): runs a claimed import in a Container. */
export interface Importer { start(server:string,job:NonNullable<Awaited<ReturnType<ImportJob['claim']>>>):Promise<{started:string}> }
Expand Down
2 changes: 1 addition & 1 deletion src/server/import/do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class RepoImport extends DurableObject<{DB:D1Database;ACTIONS_SECRET_KEY?
/** Keep this import off the container: it waits for the CLI or an owner runner. */
async local(message:string) {
await this.ctx.storage.put('dispatches',DISPATCHES)
await this.mutate(async()=>{const j=await this.ctx.storage.get<import('./job.js').Job>('job');if(j?.state==='queued')await this.ctx.storage.put('job',{...j,progress:{...j.progress,message}})})
await this.mutate(async()=>{const j=await this.ctx.storage.get<import('./job.js').Job>('job');if(j?.state==='queued')await this.ctx.storage.put('job',{...j,local:true,progress:{...j.progress,message}})})
}
cutover() {return this.mutate(()=>this.job.cutover())}
async alarm() {
Expand Down
4 changes: 2 additions & 2 deletions src/server/import/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Job {
state:'queued'|'running'|'complete'|'mirroring'|'failed'|'cutover';
progress:Progress; warnings:string[]; error:string|null;
updated:number; next:number|null; cipher:string|null;
runner?:{owner:string;id:string;lease:string}; leaseHash:string|null; expires:number; checkpoint:string; busy:boolean;
runner?:{owner:string;id:string;lease:string}; leaseHash:string|null; expires:number; checkpoint:string; busy:boolean; local?:boolean;
}
export const hash=async(s:string)=>Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',new TextEncoder().encode(s))),b=>b.toString(16).padStart(2,'0')).join('')
export class ImportJob {
Expand All @@ -29,7 +29,7 @@ export class ImportJob {
}
async status() {
const j=await this.read()
return {repository:j.repository,source:j.source,mirror:j.mirror,state:j.state,progress:j.progress,warnings:j.warnings,error:j.error,updated_at:new Date(j.updated).toISOString(),next_sync:j.next?new Date(j.next).toISOString():null,summary:j.summary}
return {repository:j.repository,source:j.source,mirror:j.mirror,state:j.state,progress:j.progress,warnings:j.warnings,error:j.error,updated_at:new Date(j.updated).toISOString(),next_sync:j.next?new Date(j.next).toISOString():null,summary:j.summary,...(j.local?{local:true}:{})}
}
async claim(runner?:Job["runner"]) {
const j=await this.read()
Expand Down
Loading