Skip to content

feat: automatically update pre-commit config with posthog package for Python projects#266

Open
rnegron wants to merge 4 commits intoPostHog:mainfrom
rnegron:feat/pre-commit-config-update
Open

feat: automatically update pre-commit config with posthog package for Python projects#266
rnegron wants to merge 4 commits intoPostHog:mainfrom
rnegron:feat/pre-commit-config-update

Conversation

@rnegron
Copy link

@rnegron rnegron commented Feb 8, 2026

Summary

  • Adds a new wizard step that updates .pre-commit-config.yaml (if available) to include the posthog Python package in additional_dependencies (for type-checking hooks, i.e mypy, pyright, pytype).
  • Currently only runs on supported Python frameworks: Django, Flask, FastAPI, and (of course) Python

Background

I ran the PostHog wizard on a local Django project and everything worked great! Except that my pre-commit mypy hook failed... Adding this step to hopefully solve for anyone else that might run into this in the future!

Test plan

  • Manually tested on said Django project via pnpm link --global in this repo and then wizard --region us in the local Django project.

Here is a snippet of final wizard output (see last point):

Successfully installed PostHog!

What the agent did:
• Analyzed your Django REST Framework project structure
• Installed the PostHog Python package
• Configured PostHog in your Django settings
• Added PostHog middleware for automatic event tracking
• Added environment variables to .env file
• Updated .pre-commit-config.yaml with posthog dependency

Copilot AI review requested due to automatic review settings February 8, 2026 23:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new wizard step to automatically update an existing pre-commit configuration for Python projects so type-checking hooks include the posthog package in additional_dependencies, preventing mypy/pyright/pytype failures after installing PostHog.

Changes:

  • Added updatePreCommitConfigStep to parse .pre-commit-config.(yml|yaml) and append posthog to relevant hooks’ additional_dependencies.
  • Wired the new step into the agent runner for Python integrations (Django/Flask/FastAPI/Python) and reflected it in the wizard outro.
  • Added Jest test coverage and introduced the yaml dependency.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/steps/update-pre-commit-config.ts Implements YAML parsing + mutation of pre-commit config to add posthog to type-checking hooks.
src/steps/index.ts Exports the new step from the steps barrel.
src/steps/tests/update-pre-commit-config.test.ts Tests config discovery, idempotency, formatting preservation, and error paths.
src/lib/agent-runner.ts Runs the new step for Python integrations and includes it in the outro changes list.
package.json Adds yaml as a direct dependency.
pnpm-lock.yaml Locks the new yaml dependency/version.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@rnegron
Copy link
Author

rnegron commented Feb 8, 2026

by the way, I am aware there is some ongoing work around how the wizard handles .env files (#263), and this step is effectively modeled after that existing add-or-update-environment-variables step.

I think pre-commit config files are less of a concern than env files when it comes to security and exposure, so I figured I would submit this change anyway in case it would be useful!

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.

1 participant