diff --git a/backend/src/services/GiteaService.ts b/backend/src/services/GiteaService.ts index f5c21bf..0087009 100644 --- a/backend/src/services/GiteaService.ts +++ b/backend/src/services/GiteaService.ts @@ -389,7 +389,22 @@ class GiteaService { for (const ep of result.rows) { try { - await this.commitEndpointFiles(ep, cfg.prod_branch || 'main', `Sync: ${ep.name}`); + const sha = await this.commitEndpointFiles(ep, cfg.prod_branch || 'main', `Sync: ${ep.name}`); + // Mark published version as synced + if (sha && ep.published_version_id) { + await mainPool.query( + 'UPDATE endpoint_versions SET gitea_commit_sha = $1 WHERE id = $2', + [sha, ep.published_version_id] + ); + } else if (sha) { + // No published version yet — mark the latest version + await mainPool.query( + `UPDATE endpoint_versions SET gitea_commit_sha = $1 + WHERE endpoint_id = $2 AND gitea_commit_sha IS NULL + ORDER BY version_number DESC LIMIT 1`, + [sha, ep.id] + ); + } synced++; } catch (err: any) { errors.push(`${ep.name}: ${err.message}`);