acd3305a3f
getCommits ahora recibe page/limit y devuelve {commits, totalPages} (del
header X-PageCount de Gitea). La página lee ?page, muestra 10 commits y usa
el componente Pagination (Anterior/1 2 3…/Siguiente).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
// Changelog desde la API de Gitea (commits del repo).
|
|
const GITEA = process.env.GITEA_URL || 'https://git.nightspire.gg'
|
|
const REPO = process.env.GITEA_REPO || 'Inna/NovaWoW'
|
|
|
|
export interface Commit {
|
|
sha: string
|
|
shortSha: string
|
|
title: string
|
|
body: string
|
|
author: string
|
|
date: string
|
|
url: string
|
|
}
|
|
|
|
interface GiteaCommit {
|
|
sha: string
|
|
html_url: string
|
|
created?: string
|
|
commit?: { message?: string; author?: { name?: string; date?: string } }
|
|
author?: { login?: string } | null
|
|
}
|
|
|
|
export async function getCommits(page = 1, limit = 10): Promise<{ commits: Commit[]; totalPages: number }> {
|
|
try {
|
|
const res = await fetch(`${GITEA}/api/v1/repos/${REPO}/commits?page=${page}&limit=${limit}`, {
|
|
headers: { Accept: 'application/json' },
|
|
// Cache corto para no golpear Gitea en cada visita.
|
|
next: { revalidate: 300 },
|
|
})
|
|
if (!res.ok) return { commits: [], totalPages: 1 }
|
|
const totalPages = Math.max(1, Number(res.headers.get('x-pagecount') || '1'))
|
|
const data = (await res.json()) as GiteaCommit[]
|
|
const commits = data.map((c) => {
|
|
const msg = c.commit?.message ?? ''
|
|
const lines = msg.split('\n')
|
|
const title = lines[0].trim()
|
|
// Cuerpo sin la primera línea y sin los trailers (Co-Authored-By, etc.).
|
|
const body = lines
|
|
.slice(1)
|
|
.filter((l) => !/^Co-Authored-By:/i.test(l.trim()) && !/Generated with \[?Claude/i.test(l))
|
|
.join('\n')
|
|
.trim()
|
|
return {
|
|
sha: c.sha,
|
|
shortSha: c.sha.slice(0, 7),
|
|
title,
|
|
body,
|
|
author: c.commit?.author?.name || c.author?.login || '',
|
|
date: c.commit?.author?.date || c.created || '',
|
|
url: c.html_url,
|
|
}
|
|
})
|
|
return { commits, totalPages }
|
|
} catch {
|
|
return { commits: [], totalPages: 1 }
|
|
}
|
|
}
|