W n8n route
This commit is contained in:
parent
cdd4dc127f
commit
a39be32d6b
@ -291,7 +291,8 @@
|
|||||||
460
|
460
|
||||||
],
|
],
|
||||||
"id": "6b7f99e2-8dcc-48b0-8ef5-dcaaa3acf1ad",
|
"id": "6b7f99e2-8dcc-48b0-8ef5-dcaaa3acf1ad",
|
||||||
"continueOnFail": true
|
"continueOnFail": true,
|
||||||
|
"errorMessage": "={{ $json.error?.message || 'Unknown error creating Git repository' }}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
|||||||
@ -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({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
status: 'success',
|
status: 'success',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user