Skip to content

chore: Add prek hooks - #953

Merged
marandaneto merged 11 commits into
PostHog:mainfrom
philippsuess:chore/add-pre-commit-hooks
Oct 29, 2026
Merged

marandaneto merged 11 commits into
PostHog:mainfrom
philippsuess:chore/add-pre-commit-hooks

Conversation

@philippsuess

@philippsuess philippsuess commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Hey! I noticed this repository doesn't use git prek hooks yet, so I put together a very minimal set as a starting point.

What's included

  • prek.toml with these built-in hooks:
    • check-case-conflict
    • check-merge-conflict
    • check-symlinks
    • check-xml
    • check-yaml
    • detect-private-key
  • A protect-main-branch pre-push hook (scripts/check-protected-branch.sh, same as posthog-js) that rejects pushes while on main. It is skipped in GitHub Actions.
  • make bootstrap now installs prek and runs prek install, which installs both the pre-commit and pre-push hooks

Hooks are opt-in per clone, and CI stays the source of truth.

💚 How did you test it?

  • Ran prek validate-config prek.toml and prek run --all-files; the hooks pass on the current tree.
  • Verified the hook blocks a commit containing an invalid YAML file.
  • Verified protect-main-branch passes on a feature branch, fails on main with exit 1, and exits 0 when GITHUB_ACTIONS=true.
  • Verified prek install installs both .git/hooks/pre-commit and .git/hooks/pre-push in a fresh clone.
  • Ran the new brew install prek and prek install bootstrap lines directly. A full make bootstrap run stopped earlier at gem install cocoapods due to system Ruby permissions on my machine, unrelated to this change.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

Not needed: tooling-only change, no releasable SDK change.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Drafted with Claude Code at the author's direction. The hook set was kept intentionally small.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@philippsuess
philippsuess requested a review from a team as a code owner October 17, 2026 08:46
@philippsuess
philippsuess marked this pull request as draft October 17, 2026 08:47
philippsuess and others added 2 commits October 17, 2026 10:48
@philippsuess
philippsuess marked this pull request as ready for review October 17, 2026 08:52
@marandaneto

Copy link
Copy Markdown
Member

we use https://github.com/j178/prek for some other sdks
can we use prek here as well? if not, why?

@philippsuess

philippsuess commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Sorry for the late reply @marandaneto. Thanks for pointing it out. Yes, of course, we can use prek. I have never used it. I will update the PR, shortly.

@philippsuess

Copy link
Copy Markdown
Contributor Author

Good call, switched to prek. It reads the same .pre-commit-config.yaml, so the hook config is unchanged; make bootstrap now runs brew install prek and prek install, and CONTRIBUTING.md documents it.

Verified locally with prek 0.5.7: prek run --all-files passes, and an invalid YAML file is blocked on commit. One gotcha, documented: if someone already ran pre-commit install, they need prek install --force, otherwise the old hook runs in migration mode and blocks commits.

@philippsuess philippsuess changed the title chore: add pre-commit hooks chore: Add prek hooks Oct 28, 2026
#!/bin/sh

# Skip protection if running in GitHub Actions
if [ "$GITHUB_ACTIONS" = "true" ]; then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marandaneto
marandaneto enabled auto-merge (squash) October 29, 2026 13:30
@marandaneto
marandaneto merged commit 94488d4 into PostHog:main Oct 29, 2026
48 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.

2 participants