From b63117694bd1f9e21df68f41447174636469eefe Mon Sep 17 00:00:00 2001 From: amaliadwiy Date: Wed, 29 Apr 2026 13:56:23 +0800 Subject: [PATCH] feat: add /api/system/version endpoint with changelog Mengembalikan versi aplikasi, git commit hash, branch aktif, dan 20 commit terakhir untuk memverifikasi apakah staging/production sudah terupdate. Co-Authored-By: Claude Sonnet 4.6 --- src/app.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/app.ts b/src/app.ts index 5c70a0c..a5a55ad 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1010,6 +1010,39 @@ export function createApp() { tags: ['System'], }, }) + .get('/api/system/version', async () => { + const pkg = await Bun.file('./package.json').json() + let commit = 'unknown' + let branch = 'unknown' + let changelog: { hash: string; date: string; author: string; message: string }[] = [] + try { + const commitProc = Bun.spawn(['git', 'rev-parse', '--short', 'HEAD'], { stdout: 'pipe', stderr: 'pipe' }) + commit = (await new Response(commitProc.stdout).text()).trim() + const branchProc = Bun.spawn(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], { stdout: 'pipe', stderr: 'pipe' }) + branch = (await new Response(branchProc.stdout).text()).trim() + const logProc = Bun.spawn( + ['git', 'log', '--pretty=format:%h|%aI|%an|%s', '-20'], + { stdout: 'pipe', stderr: 'pipe' }, + ) + const logText = (await new Response(logProc.stdout).text()).trim() + changelog = logText.split('\n').filter(Boolean).map(line => { + const [hash, date, author, ...msgParts] = line.split('|') + return { hash, date, author, message: msgParts.join('|') } + }) + } catch { /* git not available */ } + return { + version: pkg.version as string, + commit, + branch, + changelog, + } + }, { + detail: { + summary: 'Version Info', + description: 'Mengembalikan versi aplikasi, git commit hash, branch aktif, dan 20 commit terakhir sebagai changelog.', + tags: ['System'], + }, + }) // ─── Example API ─────────────────────────────────── .get('/api/hello', () => ({