Skip to content

feat: add lefthook pre-commit hook with gitleaks secret scanning - #384

Merged
ochiu merged 1 commit into
bcgov:mainfrom
panish16:feat/git-hooks-gitleaks
Oct 2, 2026
Merged

ochiu merged 1 commit into
bcgov:mainfrom
panish16:feat/git-hooks-gitleaks

Conversation

@panish16

@panish16 panish16 commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Part of the Git Hooks RFC rollout (bcgov/entity#34619).

Adds a pre-commit hook that runs gitleaks on staged changes, same setup already merged in bcgov/registries-search#366, bcgov/bcros-common#313 and bcgov/entity#35072.

  • package.json - hooks-only, just installs lefthook. Subfolders keep managing their own deps.
  • lefthook.yml - secret scan only via npx gitleaks-secret-scanner
  • .gitleaks.toml - gitleaks default rules, lockfiles + this config allowlisted
  • pnpm-workspace.yaml - allowBuilds: lefthook: false, so lefthook's own postinstall doesn't run (prepare handles the install). Without this pnpm v11 fails the root install with ERR_PNPM_IGNORED_BUILDS.

prepare is git --version && lefthook install || exit 0, so it skips when there's no git (build images) and works on Windows too.

To get the hook: run pnpm install at the repo root once.

Subfolder pnpm apps (web/pay-ui, web/express-checkout) each have their own pnpm-workspace.yaml, so they keep using their own settings - checked with pnpm config get allowBuilds in each.

No CI/CD workflow installs at the repo root - CI runs in each app's own folder.

Tested

Real git commit on Windows, pnpm 11.9.0 with default build-script approval:

  • root pnpm install exits 0, hook installed
  • fake GitHub token at root and in web/ → blocked
  • clean change, YOUR_API_KEY placeholder → commit fine

Part of the Git Hooks RFC rollout (bcgov/entity#34619). Adds a
hooks-only root package.json (no app code at root) that installs
lefthook, which runs gitleaks against staged changes on commit.

prepare skips lefthook when git is absent and works under both cmd.exe
and POSIX sh. lefthook's own postinstall is disabled via allowBuilds in
pnpm-workspace.yaml since prepare handles installation.
@ochiu
ochiu merged commit f9e2dcb into bcgov:main Oct 2, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants