This commit is contained in:
2025-04-17 21:45:52 +08:00
parent da77ff4bc8
commit 0f22bcee8c
4 changed files with 126 additions and 0 deletions

34
api/gitea-webhook.js Normal file
View File

@@ -0,0 +1,34 @@
// api/gitea-webhook.js
import axios from 'axios';
export default async function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).send('Only POST requests allowed');
}
// 可选校验 Gitea 签名等
console.log('🔔 Received Gitea webhook');
const VERCEL_TOKEN = process.env.VERCEL_TOKEN;
const PROJECT_NAME = 'your-project-name'; // Vercel 项目名
const TEAM_ID = 'your-team-id-or-null'; // 如果是团队项目,写 team id否则 null
try {
const result = await axios.post('https://api.vercel.com/v13/deployments', {
name: PROJECT_NAME,
target: 'production'
}, {
headers: {
Authorization: `Bearer ${VERCEL_TOKEN}`,
'Content-Type': 'application/json'
},
params: TEAM_ID ? { teamId: TEAM_ID } : {}
});
console.log('✅ Deploy triggered:', result.data.url);
res.status(200).json({ message: 'Deploy triggered', url: result.data.url });
} catch (err) {
console.error('❌ Error triggering deploy:', err.response?.data || err.message);
res.status(500).json({ error: 'Failed to trigger deploy' });
}
}