logs
This commit is contained in:
parent
cc80fe9263
commit
c85e0dbd71
|
@ -14,6 +14,7 @@ const COMMIT_TTL = 30 * 24 * 60 * 60 * 1000; // 30 days
|
|||
* @param {Object} res - Express response object
|
||||
*/
|
||||
const cleanup = (req, res) => {
|
||||
console.log('🧹 Starting cleanup')
|
||||
const now = Date.now();
|
||||
let cleaned = 0;
|
||||
|
||||
|
@ -25,6 +26,11 @@ const cleanup = (req, res) => {
|
|||
}
|
||||
}
|
||||
|
||||
console.log('🧹 Cleanup completed:', {
|
||||
cleaned,
|
||||
remaining: reportedCommits.size
|
||||
})
|
||||
|
||||
res.status(200).json({ cleaned });
|
||||
};
|
||||
|
||||
|
@ -35,9 +41,23 @@ const cleanup = (req, res) => {
|
|||
*/
|
||||
const webhook = async (req, res) => {
|
||||
try {
|
||||
console.log('🎯 Webhook received:', {
|
||||
headers: req.headers,
|
||||
method: req.method,
|
||||
path: req.path
|
||||
})
|
||||
|
||||
const payload = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
|
||||
console.log('📦 Payload type:', {
|
||||
isGitea: !!payload?.repository?.owner?.username,
|
||||
hasCommits: Array.isArray(payload?.commits),
|
||||
repoName: payload?.repository?.full_name,
|
||||
eventType: req.headers['x-github-event'] || req.headers['x-gitea-event'] || 'unknown'
|
||||
})
|
||||
|
||||
if (!payload || !payload.repository) {
|
||||
console.warn('❌ Invalid payload:', payload)
|
||||
return res.status(400).send('Invalid webhook payload')
|
||||
}
|
||||
|
||||
|
@ -47,12 +67,15 @@ const webhook = async (req, res) => {
|
|||
: handleGithub(payload, reportedCommits, commitTimestamps)
|
||||
|
||||
if (!message) {
|
||||
console.log('⏭️ No new commits to report')
|
||||
return res.status(200).send('No new commits to report')
|
||||
}
|
||||
|
||||
console.log('📨 Sending message to Telegram:', message)
|
||||
|
||||
// Send to Telegram
|
||||
const telegramUrl = `https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`
|
||||
await fetch(telegramUrl, {
|
||||
const response = await fetch(telegramUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
|
@ -63,9 +86,15 @@ const webhook = async (req, res) => {
|
|||
})
|
||||
})
|
||||
|
||||
const telegramResult = await response.json()
|
||||
console.log('✅ Telegram response:', telegramResult)
|
||||
|
||||
res.status(200).send('ok')
|
||||
} catch (error) {
|
||||
console.error('Error processing webhook:', error)
|
||||
console.error('💥 Error processing webhook:', error, {
|
||||
body: req.body,
|
||||
headers: req.headers
|
||||
})
|
||||
res.status(500).send(`Error: ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user