feat: add repository health monitoring endpoint (#9)

This commit is contained in:
2026-03-04 18:11:03 -08:00
parent c310b22e8e
commit cd53a4e612

View File

@@ -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');
}