W n8n route

This commit is contained in:
alma 2025-05-24 08:47:59 +02:00
parent cdd4dc127f
commit a39be32d6b
2 changed files with 62 additions and 1 deletions

View File

@ -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": {

View File

@ -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',