diff --git a/updater/src/index.js b/updater/src/index.js index a53750c..cbe3d8c 100644 --- a/updater/src/index.js +++ b/updater/src/index.js @@ -98,7 +98,9 @@ async function getForgejoCommit(repo) { const res = await fetch(`${FORGEJO_URL}/api/v1/repos/${FORGEJO_ORG}/${repo}/commits?limit=1`, { headers }) if (!res.ok) return null 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 { return null } @@ -108,18 +110,24 @@ async function refreshStatus(repo) { const target = getDeployTarget(repo) if (!target) return null - const [current, latest] = await Promise.all([ - sshGet(target.host, `git -C ${target.path} rev-parse HEAD 2>/dev/null || echo not-deployed`), + const [currentRaw, latest] = await Promise.all([ + sshGet(target.host, `git -C ${target.path} log -1 --format='%H|%cI' HEAD 2>/dev/null || echo not-deployed`), 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 = { repo, host: target.host, - currentCommit: deployed ? current.slice(0, 12) : (current || 'unreachable'), - latestCommit: latest ? latest.slice(0, 12) : 'unknown', - updateAvailable: !!(deployed && latest && current && latest !== current), + currentCommit: deployed ? currentSha.slice(0, 12) : (currentRaw || 'unreachable'), + currentCommitAt: currentTimestamp || null, + latestCommit: latest ? latest.sha.slice(0, 12) : 'unknown', + latestCommitAt: latest?.timestamp || null, + updateAvailable: !!(deployed && latest && currentSha && latest.sha !== currentSha), deployed, checkedAt: new Date().toISOString(), }