Hook that uses OpenAI's ChatGPT API to generate a summary of changes made to a codebase and use it to populate the commit message automatically.
Commit message structure based on Commit message with scope
convention from Conventional Commits.
This hook runs on the prepare-commit-msg
stage and requires to be explicitly enabled. The standard pre-commit install
doesn't support the hook. To enable prepare-commit-msg support, add default_install_hook_types
section with hook configuration:
Add to your .pre-commit-config.yaml
default_install_hook_types:
- pre-commit
- prepare-commit-msg
repos:
- repo: https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks
rev: v0.1.3 # Use the ref you want to point at, see ⚠️ NOTE below!
hooks:
- id: chatgpt-commit-message
⚠️ NOTEFor the
rev:
always try to use the latest version. You can check the latest release under GitHub Releases
and run:
pre-commit install
The hook uses global configuration settings or arguments specified in the 📥 Prerequisites setup and 🛠️ Advanced configuration sections and takes own optional arguments listed below:
Name | Type | Default | Description |
---|---|---|---|
--max-char-count |
int |
10000 | Send git diff --staged --stat results instead of the full diff of staged changes if the diff length is more than NNN characters |
--emoji |
bool |
false | Use GitMoji to preface commit message. Flag type argument, if it exists, it's True.💥 |
--description |
bool |
false | Add short changes summary description to the commit (see, Commit message with description). Flag type argument, if it exists, it's True. |
Example:
default_install_hook_types:
- pre-commit
- prepare-commit-msg
repos:
- repo: https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks
rev: v0.1.3 # Use the ref you want to point at, see ⚠️ NOTE below!
hooks:
- id: chatgpt-commit-message
args:
- "--emoji"
- "--max-char-count"
- "500"
- "--description"
Staged changes and commit:
git add <files...>
git commit
Example commit message prefaced with GitMoji and description:
✨ feat(scope): add pre-commit hooks and VSCode settings
This commit adds pre-commit hooks and VSCode settings to improve code quality and consistency.
The `.pre-commit-hooks.yaml` file contains hooks for linting, formatting, and checking for security vulnerabilities.
The `.vscode/settings.json` file includes settings for linting and formatting on save.
If your commit message includes one of the keywords: #no-ai
, #no-openai
, #no-chatgpt
, #no-gpt
, #skip-ai
, #skip-openai
, #skip-chatgpt
, #skip-gpt
, then the commit suggestion will be skipped without any request to OpenAI service, and the pre-commit hook will pass.
Example:
Update typos in docs #no-gpt