From c85e0dbd713bf0bcd98e400c26b121f167769905 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 19 Feb 2025 02:20:42 +0300 Subject: [PATCH] logs --- api/webhook.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/api/webhook.js b/api/webhook.js index 18439ae..a811e63 100644 --- a/api/webhook.js +++ b/api/webhook.js @@ -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}`) } }