From 715a5bdfb516f7178814095162565614fcbeda29 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 14 May 2026 03:51:55 +0000 Subject: [PATCH] feat: implement GitHub repo creation with AI-generated scaffold files After scaffold generation succeeds, the results page now calls /api/github/create-repo with the AI-generated files instead of stopping at an alert. The create-repo route accepts an optional scaffoldFiles parameter; when provided it uses those files directly rather than generating hardcoded templates, so the created repository reflects the Claude-generated scaffold. https://claude.ai/code/session_01P7WFRLD4UQoEpoZKD3RbEe --- app/api/github/create-repo/route.ts | 21 ++++++++++++++++----- app/dashboard/results/page.tsx | 26 ++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/app/api/github/create-repo/route.ts b/app/api/github/create-repo/route.ts index 1295547..131c4d6 100644 --- a/app/api/github/create-repo/route.ts +++ b/app/api/github/create-repo/route.ts @@ -19,9 +19,10 @@ export async function POST(request: NextRequest) { return NextResponse.json({ error: 'Not authenticated' }, { status: 401 }) } - const { app, repoName } = (await request.json()) as { + const { app, repoName, scaffoldFiles } = (await request.json()) as { app: TemplateApp repoName: string + scaffoldFiles?: Record } if (!repoName || repoName.trim().length === 0) { @@ -54,16 +55,17 @@ export async function POST(request: NextRequest) { const newRepo = await createRepoRes.json() - // Generate initial code template - const templateFiles = generateTemplateFiles(app) + const filesToCreate = scaffoldFiles + ? normalizeScaffoldFiles(scaffoldFiles) + : generateTemplateFiles(app) // Create files in the new repository - for (const [fileName, content] of Object.entries(templateFiles)) { + for (const [fileName, content] of Object.entries(filesToCreate)) { await createFileInRepo( githubUsername, repoName, fileName, - content as string, + content, accessToken ) } @@ -107,6 +109,15 @@ async function createFileInRepo( ) } +function normalizeScaffoldFiles(files: Record): Record { + return Object.fromEntries( + Object.entries(files).map(([path, content]) => [ + path, + typeof content === 'string' ? content : JSON.stringify(content, null, 2), + ]) + ) +} + function generateTemplateFiles(app: TemplateApp): Record { return { 'README.md': `# ${app.app_name} diff --git a/app/dashboard/results/page.tsx b/app/dashboard/results/page.tsx index 6232a5b..4371069 100644 --- a/app/dashboard/results/page.tsx +++ b/app/dashboard/results/page.tsx @@ -48,8 +48,30 @@ export default function ResultsPage() { const data = await res.json() if (data.success) { - alert(`Scaffold generated for ${app.name}! Creating repository...`) - // TODO: Create GitHub repo with scaffold + const repoName = app.name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '') + const repoRes = await fetch('/api/github/create-repo', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + app: { + app_name: app.name, + app_type: app.category, + description: app.description, + technologies: app.technologies, + difficulty_level: app.estimatedBuildTime, + ai_explanation: '', + missing_files: app.missingFiles, + }, + repoName, + scaffoldFiles: data.scaffold?.files, + }), + }) + const repoData = await repoRes.json() + if (repoData.success) { + alert(`Repository created: ${repoData.repository.url}`) + } else { + alert(`Scaffold generated but repo creation failed: ${repoData.error}`) + } } } catch (error) { console.error('Scaffold generation failed:', error)