From a39be32d6b634574207d993bf25872e3b71aa97d Mon Sep 17 00:00:00 2001 From: alma Date: Sat, 24 May 2025 08:47:59 +0200 Subject: [PATCH] W n8n route --- My_workflow_49.json | 3 +- app/api/missions/route.ts | 60 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/My_workflow_49.json b/My_workflow_49.json index 8294cfdf..7e4a8eaf 100644 --- a/My_workflow_49.json +++ b/My_workflow_49.json @@ -291,7 +291,8 @@ 460 ], "id": "6b7f99e2-8dcc-48b0-8ef5-dcaaa3acf1ad", - "continueOnFail": true + "continueOnFail": true, + "errorMessage": "={{ $json.error?.message || 'Unknown error creating Git repository' }}" }, { "parameters": { diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index dba6e36f..57910f36 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -351,6 +351,66 @@ export async function POST(request: Request) { } } + // Handle Git repository creation + if (mission.services.includes('Gite')) { + try { + // Sanitize the mission name similar to n8n workflow + const sanitizedName = mission.name.toLowerCase() + .split('') + .map(c => { + if (c >= 'a' && c <= 'z') return c; + if (c >= '0' && c <= '9') return c; + if (c === ' ' || c === '-') return c; + return ''; + }) + .join('') + .split(' ') + .filter(Boolean) + .join('-'); + + const giteaResponse = await fetch(`${process.env.GITEA_API_URL}/user/repos`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `token ${process.env.GITEA_API_TOKEN}` + }, + body: JSON.stringify({ + name: sanitizedName, + private: true, + auto_init: true, + avatar_url: mission.logo || null + }) + }); + + if (!giteaResponse.ok) { + const errorData = await giteaResponse.json(); + console.error('Git repository creation failed:', { + status: giteaResponse.status, + statusText: giteaResponse.statusText, + error: errorData + }); + throw new Error(`Git repository creation failed: ${errorData.message || giteaResponse.statusText}`); + } + + const giteaData = await giteaResponse.json(); + + // Update the mission with the Git repository URL + await prisma.mission.update({ + where: { id: mission.id }, + data: { + giteaRepositoryUrl: giteaData.html_url + } + }); + + } catch (error) { + console.error('Error creating Git repository:', error); + if (error instanceof Error) { + throw new Error(`Failed to create Git repository: ${error.message}`); + } + throw new Error('Failed to create Git repository: Unknown error'); + } + } + return NextResponse.json({ success: true, status: 'success',