Skip to content

Commit a8d5842

Browse files
committed
chore(hooks): DRY API docs using shared helper; avoid direct process.exit in pre-commit
1 parent 90b108f commit a8d5842

File tree

2 files changed

+9
-35
lines changed

2 files changed

+9
-35
lines changed

booster/.husky/pre-commit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ await runHook(GitHook.PreCommit, async () => {
2323

2424
if (files.length === 0) {
2525
log.info('No files staged for commit. Skipping quality checks.')
26-
process.exit(0)
26+
return true
2727
}
2828

2929
log.info(`Found ${files.length} staged file(s): ${files.join(', ')}`)

booster/.husky/pre-push.ts

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* - API Documentation generation
1010
*/
1111
import { $, fs } from 'zx'
12-
import { GitHook, log, runHook, runWithRunner } from './shared/index.ts'
12+
import { GitHook, isSkipped, log, runHook, runWithRunner, generateApiDocs } from './shared/index.ts'
1313

1414
const SKIP_COMMIT_MSG = 'chore: update API documentation'
1515

@@ -45,40 +45,14 @@ async function runTests(): Promise<boolean> {
4545
}
4646

4747
async function handleApiDocs(): Promise<boolean> {
48-
log.tool('API Documentation', 'Generating OpenAPI specification...')
49-
try {
50-
if (!(await fs.pathExists('vendor/zircote/swagger-php'))) {
51-
log.info('swagger-php not installed -> skipping API docs.')
52-
return true
53-
}
54-
55-
await runWithRunner(['composer', 'generate-api-spec'])
56-
57-
// Check if openapi.yml changed
58-
const diff = await $`git diff --name-only`
59-
if (!diff.stdout.includes('documentation/openapi.yml')) {
60-
log.success('API documentation check passed (no changes)')
61-
return true
62-
}
63-
64-
log.info('API spec changed, regenerating HTML...')
65-
await runWithRunner(['pnpm', 'generate:api-doc:html'])
66-
67-
// Check for changes in documentation files
68-
const status = await $`git status --porcelain documentation/openapi.html documentation/openapi.yml`
69-
if (status.stdout.trim() !== '') {
70-
log.info('API documentation is outdated. Updating and committing...')
71-
72-
await $`git add documentation/openapi.html documentation/openapi.yml`
73-
// Skip pre-commit (linting) but run commit-msg (ticket appending)
74-
await $`SKIP_PRECOMMIT=1 git commit -m ${SKIP_COMMIT_MSG}`
75-
76-
log.success('API documentation updated and committed.')
77-
log.warn('The new documentation commit was created AFTER the push started.')
78-
log.warn('Your code has been pushed, but you must run "git push" AGAIN to send the documentation update.')
79-
return true
80-
}
48+
// Allow skipping API docs generation explicitly via env var
49+
if (isSkipped('api_docs')) {
50+
log.info('Skipping API docs generation (SKIP_API_DOCS environment variable set)')
51+
return true
52+
}
8153

54+
try {
55+
await generateApiDocs()
8256
return true
8357
} catch (e) {
8458
log.error('API spec generation failed')

0 commit comments

Comments
 (0)