Skip to content

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

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

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

Conversation

@panish16

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 as 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.
  • document-service/documents-common/layers/base/pnpm-workspace.yaml - that layer has its own pnpm lockfile but no workspace file, so pnpm would pick up the new root one and silently install nothing there ("Already up to date"). Giving it its own packages: [] keeps it standalone. Checked: installing in that folder gives identical results to main (same 936 packages, same pre-existing ignored-builds output). documents-ui already has its own workspace file so it's unaffected.

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.

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, in notify-service/, in document-service/ → blocked
  • clean change → commit fine

No CI/CD workflow installs at the repo root (all path-scoped to service folders), so no pipeline impact.

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.

documents-common/layers/base had no pnpm-workspace.yaml of its own, so
pnpm would resolve the new root one as its workspace and install nothing
there. Give it its own (packages: []) so it stays a standalone project.
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.

3 participants