feat: add repository health monitoring endpoint (#9)
This commit is contained in:
@@ -108,6 +108,51 @@ function setupGiteaRoutes(app) {
|
|||||||
res.json({ success: true, message: 'Cache cleared' });
|
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');
|
console.log('✅ Gitea integration loaded');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user