From cd53a4e612a141f9d2953cbc81b9e46408b38e57 Mon Sep 17 00:00:00 2001 From: Christopher Mayor Date: Wed, 4 Mar 2026 18:11:03 -0800 Subject: [PATCH] feat: add repository health monitoring endpoint (#9) --- gitea-routes.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/gitea-routes.js b/gitea-routes.js index c11e696..72b3ef1 100644 --- a/gitea-routes.js +++ b/gitea-routes.js @@ -108,6 +108,51 @@ function setupGiteaRoutes(app) { res.json({ success: true, message: 'Cache cleared' }); }); + + // Repository health check + app.get('/api/gitea/health', async (req, res) => { + try { + const repos = await gitea.getRepos(); + const health = []; + + for (const repo of repos) { + const updated = new Date(repo.updated_at); + const daysSinceUpdate = Math.floor((Date.now() - updated.getTime()) / (1000 * 60 * 60 * 24)); + + let status = 'healthy'; + if (daysSinceUpdate > 30) status = 'stale'; + else if (daysSinceUpdate > 7) status = 'inactive'; + + let openPRs = 0; + try { + const prs = await gitea.getPullRequests(repo.name, 'open'); + openPRs = prs.length; + } catch {} + + health.push({ + name: repo.name, + status, + daysSinceUpdate, + updated_at: repo.updated_at, + openPRs, + html_url: repo.html_url + }); + } + + res.json({ + repos: health, + summary: { + total: health.length, + healthy: health.filter(r => r.status === 'healthy').length, + inactive: health.filter(r => r.status === 'inactive').length, + stale: health.filter(r => r.status === 'stale').length + } + }); + } catch (error) { + res.status(500).json({ error: error.message }); + } + }); + console.log('✅ Gitea integration loaded'); }