feat(updater): include commit timestamps in status response

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-02 15:58:41 +00:00
parent d9dc5bf798
commit e2a86bf30f

View file

@ -98,7 +98,9 @@ async function getForgejoCommit(repo) {
const res = await fetch(`${FORGEJO_URL}/api/v1/repos/${FORGEJO_ORG}/${repo}/commits?limit=1`, { headers }) const res = await fetch(`${FORGEJO_URL}/api/v1/repos/${FORGEJO_ORG}/${repo}/commits?limit=1`, { headers })
if (!res.ok) return null if (!res.ok) return null
const data = await res.json() const data = await res.json()
return data?.[0]?.sha || null const c = data?.[0]
if (!c) return null
return { sha: c.sha, timestamp: c.created || c.commit?.committer?.date || null }
} catch { } catch {
return null return null
} }
@ -108,18 +110,24 @@ async function refreshStatus(repo) {
const target = getDeployTarget(repo) const target = getDeployTarget(repo)
if (!target) return null if (!target) return null
const [current, latest] = await Promise.all([ const [currentRaw, latest] = await Promise.all([
sshGet(target.host, `git -C ${target.path} rev-parse HEAD 2>/dev/null || echo not-deployed`), sshGet(target.host, `git -C ${target.path} log -1 --format='%H|%cI' HEAD 2>/dev/null || echo not-deployed`),
getForgejoCommit(repo), getForgejoCommit(repo),
]) ])
const deployed = current && current !== 'not-deployed' let currentSha = null, currentTimestamp = null
if (currentRaw && currentRaw.includes('|')) {
;[currentSha, currentTimestamp] = currentRaw.split('|')
}
const deployed = !!currentSha
const entry = { const entry = {
repo, repo,
host: target.host, host: target.host,
currentCommit: deployed ? current.slice(0, 12) : (current || 'unreachable'), currentCommit: deployed ? currentSha.slice(0, 12) : (currentRaw || 'unreachable'),
latestCommit: latest ? latest.slice(0, 12) : 'unknown', currentCommitAt: currentTimestamp || null,
updateAvailable: !!(deployed && latest && current && latest !== current), latestCommit: latest ? latest.sha.slice(0, 12) : 'unknown',
latestCommitAt: latest?.timestamp || null,
updateAvailable: !!(deployed && latest && currentSha && latest.sha !== currentSha),
deployed, deployed,
checkedAt: new Date().toISOString(), checkedAt: new Date().toISOString(),
} }