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 <noreply@anthropic.com>
This commit is contained in:
33
src/app.ts
33
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', () => ({
|
||||
|
||||
Reference in New Issue
Block a user