feat: add Gitea monitoring page with repos, PRs, and activity

This commit is contained in:
2026-03-04 15:47:51 -08:00
parent ac98c3e242
commit 0e5d31aefd
4 changed files with 318 additions and 44 deletions

View File

@@ -934,6 +934,7 @@ document.addEventListener("DOMContentLoaded", () => {
if (CURRENT_PAGE === 'wiki') initWikiPage();
if (CURRENT_PAGE === 'agents') initAgentsPage();
if (CURRENT_PAGE === 'usage') initUsagePage();
if (CURRENT_PAGE === 'gitea') initGiteaPage();
});
// ============ GITEA DASHBOARD ============
@@ -1140,3 +1141,130 @@ if (document.querySelector('.gitea-dashboard')) {
}
}, 30000);
}
// ============ GITEA PAGE ============
let giteaData = { repos: [], prs: [], activity: [] };
function initGiteaPage() {
loadGiteaData();
document.getElementById('refresh-gitea')?.addEventListener('click', loadGiteaData);
// Tab switching
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const tab = e.target.dataset.tab;
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
e.target.classList.add('active');
document.getElementById(`tab-${tab}`)?.classList.add('active');
});
});
}
async function loadGiteaData() {
try {
const [swarmRes, reviewsRes, activityRes] = await Promise.all([
fetch('/api/gitea/swarm'),
fetch('/api/gitea/reviews'),
fetch('/api/gitea/activity')
]);
giteaData.repos = await swarmRes.json();
giteaData.prs = await reviewsRes.json();
giteaData.activity = await activityRes.json();
renderGiteaStats();
renderGiteaRepos();
renderGiteaPRs();
renderGiteaActivity();
} catch (err) {
console.error('Failed to load Gitea data:', err);
}
}
function renderGiteaStats() {
document.getElementById('stat-repos').textContent = giteaData.repos.length;
const totalPRs = giteaData.repos.reduce((sum, r) => sum + (r.open_prs || 0), 0);
document.getElementById('stat-prs').textContent = totalPRs;
const pendingReviews = giteaData.prs.filter(p => p.review_required).length;
document.getElementById('stat-reviews').textContent = pendingReviews;
}
function renderGiteaRepos() {
const grid = document.getElementById('repos-grid');
if (!grid) return;
if (!giteaData.repos.length) {
grid.innerHTML = '<p class="no-data">No repositories found</p>';
return;
}
grid.innerHTML = giteaData.repos.map(repo => `
<div class="repo-card">
<h4>${escapeHtml(repo.name)}</h4>
<p class="repo-fullname">${escapeHtml(repo.full_name || '')}</p>
<div class="repo-meta">
<span>⭐ ${repo.stars || 0}</span>
<span>🔀 ${repo.open_prs || 0}</span>
<span>🐛 ${repo.open_issues || 0}</span>
</div>
<div class="repo-updated">Updated: ${repo.updated_at ? new Date(repo.updated_at).toLocaleDateString() : 'N/A'}</div>
<a href="${repo.html_url}" target="_blank" class="btn-secondary">View →</a>
</div>
`).join('');
}
function renderGiteaPRs() {
const list = document.getElementById('prs-list');
if (!list) return;
// Collect all PRs from all repos
const allPRs = [];
giteaData.repos.forEach(repo => {
if (repo.prs) {
repo.prs.forEach(pr => {
allPRs.push({ ...pr, repo: repo.name });
});
}
});
if (!allPRs.length) {
list.innerHTML = '<p class="no-data">No open pull requests</p>';
return;
}
list.innerHTML = allPRs.map(pr => `
<div class="pr-item">
<div class="pr-header">
<span class="pr-number">#${pr.number}</span>
<span class="pr-title">${escapeHtml(pr.title)}</span>
<span class="pr-status ${pr.state}">${pr.state}</span>
</div>
<div class="pr-meta">
<span>📦 ${pr.repo}</span>
<span>👤 ${pr.user?.login || 'Unknown'}</span>
</div>
</div>
`).join('');
}
function renderGiteaActivity() {
const list = document.getElementById('activity-list');
if (!list) return;
if (!giteaData.activity || !giteaData.activity.length) {
list.innerHTML = '<p class="no-data">No recent activity</p>';
return;
}
list.innerHTML = giteaData.activity.slice(0, 20).map(activity => `
<div class="activity-item">
<span class="activity-type">${activity.type || '📝'}</span>
<span class="activity-desc">${escapeHtml(activity.message || activity.repo?.name || 'Activity')}</span>
<span class="activity-time">${activity.created_at ? new Date(activity.created_at).toLocaleString() : ''}</span>
</div>
`).join('');
}