Add commits-behind count to update status
Calls Forgejo compare API when an update is available to get the exact number of commits between deployed and latest — exposed as commitsBehind in the status payload. Degrades gracefully to null if the compare call fails. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
19bb4ec4d4
commit
584fe806d9
1 changed files with 17 additions and 1 deletions
|
|
@ -162,6 +162,19 @@ async function getForgejoCommit(repo) {
|
|||
}
|
||||
}
|
||||
|
||||
async function getCommitsBehind(repo, baseSha, headSha) {
|
||||
try {
|
||||
const headers = { Accept: 'application/json' }
|
||||
if (FORGEJO_TOKEN) headers['Authorization'] = `token ${FORGEJO_TOKEN}`
|
||||
const res = await fetch(`${FORGEJO_URL}/api/v1/repos/${FORGEJO_ORG}/${repo}/compare/${baseSha}...${headSha}`, { headers })
|
||||
if (!res.ok) return null
|
||||
const data = await res.json()
|
||||
return typeof data.total_commits === 'number' ? data.total_commits : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshStatus(repo) {
|
||||
const target = getDeployTarget(repo)
|
||||
if (!target) return null
|
||||
|
|
@ -178,6 +191,8 @@ async function refreshStatus(repo) {
|
|||
getForgejoCommit(repo),
|
||||
])
|
||||
const deployed = !!currentSha
|
||||
const updateAvailable = !!(deployed && latest && currentSha && latest.sha !== currentSha)
|
||||
const commitsBehind = updateAvailable ? await getCommitsBehind(repo, currentSha, latest.sha) : null
|
||||
const entry = {
|
||||
repo,
|
||||
host: target.host,
|
||||
|
|
@ -185,7 +200,8 @@ async function refreshStatus(repo) {
|
|||
currentCommitAt: currentTimestamp || null,
|
||||
latestCommit: latest ? latest.sha.slice(0, 12) : 'unknown',
|
||||
latestCommitAt: latest?.timestamp || null,
|
||||
updateAvailable: !!(deployed && latest && currentSha && latest.sha !== currentSha),
|
||||
updateAvailable,
|
||||
commitsBehind,
|
||||
deployed,
|
||||
checkedAt: new Date().toISOString(),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue