{"id":13645660,"url":"https://github.com/dariuszporowski/chatgpt-pre-commit-hooks","last_synced_at":"2025-05-12T23:21:07.370Z","repository":{"id":153534013,"uuid":"628880405","full_name":"DariuszPorowski/chatgpt-pre-commit-hooks","owner":"DariuszPorowski","description":"Pre-commit hooks collection that utilizes ChatGPT and OpenAI platform to validate changes made to the codebase.","archived":false,"fork":false,"pushed_at":"2023-11-20T13:41:50.000Z","size":1201,"stargazers_count":31,"open_issues_count":5,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-15T18:49:56.350Z","etag":null,"topics":["chatgpt","gpt","openai","pre-commit","pre-commit-hook","pre-commit-hooks"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/chatgpt-pre-commit-hooks","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DariuszPorowski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-04-17T07:10:34.000Z","updated_at":"2025-01-15T03:51:44.000Z","dependencies_parsed_at":"2024-01-14T10:01:04.850Z","dependency_job_id":"fff0ad98-ac5f-45d9-8827-7c7044aebdd0","html_url":"https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DariuszPorowski%2Fchatgpt-pre-commit-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DariuszPorowski%2Fchatgpt-pre-commit-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DariuszPorowski%2Fchatgpt-pre-commit-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DariuszPorowski%2Fchatgpt-pre-commit-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DariuszPorowski","download_url":"https://codeload.github.com/DariuszPorowski/chatgpt-pre-commit-hooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253838069,"owners_count":21972089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","gpt","openai","pre-commit","pre-commit-hook","pre-commit-hooks"],"created_at":"2024-08-02T01:02:39.232Z","updated_at":"2025-05-12T23:21:07.335Z","avatar_url":"https://github.com/DariuszPorowski.png","language":"Python","funding_links":[],"categories":["Openai"],"sub_categories":[],"readme":"# 🤖 ChatGPT / OpenAI pre-commit-hooks\n\n[![pre-commit][pre-commit-image]][pre-commit-link]\n[![PyPI - version][pypi-version-image]][pypi-version-link]\n[![PyPI - python version][pypi-pyversions-image]][pypi-pyversions-link]\n[![PyPI - downloads][pypi-stats-image]][pypi-stats-link]\n[![GitHub - CI][github-ci-image]][github-ci-link]\n\nPre-commit hooks collection that utilizes ChatGPT and OpenAI platform to validate changes made to the codebase.\n\n- [🎣 Hooks](#-hooks)\n  - [`chatgpt-commit-message`](#chatgpt-commit-message)\n- [📥 Prerequisites setup](#-prerequisites-setup)\n  - [OpenAI Platform](#openai-platform)\n  - [Azure OpenAI Service](#azure-openai-service)\n  - [Setting environment variables](#setting-environment-variables)\n  - [pre-commit setup](#pre-commit-setup)\n- [📦 Hooks setup](#-hooks-setup)\n  - [Remote repository reference (preferred)](#remote-repository-reference-preferred)\n  - [Local repository reference](#local-repository-reference)\n- [🛠️ Advanced configuration](#️-advanced-configuration)\n  - [Extra environment variables](#extra-environment-variables)\n  - [Arguments](#arguments)\n  - [`--env-prefix`](#--env-prefix)\n  - [Variables precedence](#variables-precedence)\n- [💸 Payments](#-payments)\n- [👥 Contributing](#-contributing)\n- [📄 License](#-license)\n\n## 🎣 Hooks\n\n### `chatgpt-commit-message`\n\nHook 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.\n\n- ⚙️ Read about hook's specific [configuration](https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks/blob/main/docs/chatgpt_commit_message.md).\n\n![chatgpt-commit-message](https://raw.githubusercontent.com/dariuszporowski/chatgpt-pre-commit-hooks/main/docs/assets/demos/chatgpt_commit_message.gif)\n\n## 📥 Prerequisites setup\n\nHooks support [OpenAI Platform](https://platform.openai.com) and [Azure OpenAI Service](https://azure.microsoft.com/products/cognitive-services/openai-service).\n\n### OpenAI Platform\n\nOpenAI API Key is mandatory to run hooks and has to be setup via an environment variable.\n\n1. Create your [API Key](https://platform.openai.com/account/api-keys), and get your Organization ID from [Organization settings](https://platform.openai.com/account/org-settings)\n\n    ![OpenAI API Key](https://raw.githubusercontent.com/dariuszporowski/chatgpt-pre-commit-hooks/main/assets/images/openai-platform-api-key.png)\n\n    ![OpenAI Organization ID](https://raw.githubusercontent.com/dariuszporowski/chatgpt-pre-commit-hooks/main/assets/images/openai-platform-org-id.png)\n\n1. Store values as an environment variables:\n    - `OPENAI_API_KEY` for API Key\n    - `OPENAI_ORGANIZATION` for Organization ID\n\n    Example:\n\n    ```shell\n    export OPENAI_API_KEY=\"sk-xxxxxx\"\n    export OPENAI_ORGANIZATION=\"org-xxxxxx\"\n    ```\n\n\u003e 💡 **HINT**\n\u003e\n\u003e How to setup environment variables? see: [Setting environment variables](#setting-environment-variables)\n\n### Azure OpenAI Service\n\n1. Go to [Azure Portal](https://portal.azure.com), and get `API Key`, `Endpoint`, `Model deployment name`, and `api-version`.\n\n    ![Azure OpenAI API Key and Endpoint](https://raw.githubusercontent.com/dariuszporowski/chatgpt-pre-commit-hooks/main/assets/images/azure-openai-service-key-endpoint.png)\n\n    ![Azure OpenAI Model](https://raw.githubusercontent.com/dariuszporowski/chatgpt-pre-commit-hooks/main/assets/images/azure-openai-service-models.png)\n\n    The latest supported `api-version` you can get from [Azure OpenAI Service](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#chat-completions)\n\n1. Store values as an environment variables:\n    - `OPENAI_API_TYPE` put `azure` to specified OpenAI provider\n    - `OPENAI_API_KEY` for API Key\n    - `OPENAI_API_BASE` for Endpoint\n    - `OPENAI_API_VERSION` for `api-version`\n    - `OPENAI_MODEL` for Model deployment name\n\n    Example:\n\n    ```shell\n    export OPENAI_API_TYPE=\"azure\"\n    export OPENAI_API_KEY=\"xxxxxx\"\n    export OPENAI_API_BASE=\"https://xxxxxx.openai.azure.com/\"\n    export OPENAI_API_VERSION=\"2023-03-15-preview\"\n    export OPENAI_MODEL=\"xxxxx-gpt-35-turbo\"\n    ```\n\n\u003e 💡 **HINT**\n\u003e\n\u003e How to setup environment variables? see: [Setting environment variables](#setting-environment-variables)\n\n### Setting environment variables\n\nLinux/MacOS example:\n\n```shell\nexport OPENAI_API_KEY=\"sk-xxxxxx\"\n```\n\nWindows `powershell` example:\n\n```powershell\n$env:OPENAI_API_KEY=\"sk-xxxxxx\"\n```\n\nWindows `cmd` example:\n\n```console\nset OPENAI_API_KEY=sk-xxxxxx\n```\n\n\u003e ⚠️ **NOTE**\n\u003e\n\u003e The above example stores the environment variable temporarily for the current session. To store it permanently, please follow [Best Practices for API Key Safety](https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety)\n\n### pre-commit setup\n\nBefore you start, ensure you have `pre-commit` installed in your repository. Below is just an essential quick start. Follow official pre-commit [install](https://pre-commit.com/#install) documentation for advanced scenarios.\n\n```shell\n# install using pip\npip install pre-commit\n\n# check if working - expected print with version like `pre-commit 3.2.2`\npre-commit --version\n```\n\nAdd to your `.pre-commit-config.yaml` top level `default_install_hook_types` section (for more information, follow [Confining hooks to run at certain stages](https://pre-commit.com/#confining-hooks-to-run-at-certain-stages))\n\n```yaml\ndefault_install_hook_types:\n  - pre-commit # this is default hook type, equivalent to classic `pre-commit install` command\n  - prepare-commit-msg # this type is not enabled by default, please enable it - equivalent to `pre-commit install --hook-type prepare-commit-msg` command\n  - ... # rest of hook types what are you using, if any\n```\n\nnext:\n\n```shell\n# setup the git repo for hooks\npre-commit install\n\n# (optional) periodically run updates to your pre-commit config to make sure you always have the latest version of the hooks\npre-commit autoupdate\n```\n\n## 📦 Hooks setup\n\n### Remote repository reference (preferred)\n\nAdd to your `.pre-commit-config.yaml`\n\n```yaml\ndefault_install_hook_types:\n  - pre-commit\n  - prepare-commit-msg\nrepos:\n  - repo: https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks\n    rev: vX.Y.Z  # Use the ref you want to point at, see ⚠️ NOTE below!\n    hooks:\n      - id: \u003cid1\u003e # follow 🎣 Hooks section to see available hooks IDs\n      - id: \u003cid2\u003e # follow 🎣 Hooks section to see available hooks IDs\n      - id: ...\n```\n\nExample:\n\n```yaml\ndefault_install_hook_types:\n  - pre-commit\n  - prepare-commit-msg\nrepos:\n  - repo: https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks\n    rev: v0.1.3\n    hooks:\n      - id: chatgpt-commit-message\n```\n\n\u003e ⚠️ **NOTE**\n\u003e\n\u003e For the `rev:` always try to use the latest version. You can check the latest release under [GitHub Releases](https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks/releases/latest)\n\n### Local repository reference\n\n1. Install or add [PyPI](https://pypi.org/project/chatgpt-pre-commit-hooks) package to your project.\n\n   - if you are using [pip](https://pip.pypa.io):\n\n     ```shell\n     pip install --upgrade chatgpt-pre-commit-hooks\n     ```\n\n   - or include it in a `requirements.txt` file in your project:\n\n     ```text\n     chatgpt-pre-commit-hooks~=0.1.3\n     ```\n\n      and run:\n\n     ```shell\n     pip install -r requirements.txt\n     ```\n\n   - or, even better, in the `dev` section of your `pyproject.toml` file:\n\n     ```toml\n     [project.optional-dependencies]\n     dev = [\"chatgpt-pre-commit-hooks\"]\n     ```\n\n      and run:\n\n     ```shell\n     pip install .[dev]\n     ```\n\n   - or, if you are using [poetry](https://python-poetry.org) as a package manager:\n\n     ```shell\n     poetry add chatgpt-pre-commit-hooks --group dev\n     ```\n\n1. Add to your `.pre-commit-config.yaml`\n\n    ```yaml\n    default_install_hook_types:\n      - pre-commit\n      - prepare-commit-msg\n    repos:\n      - repo: local\n        hooks:\n          - id: \u003cid\u003e # follow 🎣 Hooks section to see available hooks IDs\n            name: \u003cname\u003e # any name you'd like to set\n            entry: chatgpt-pre-commit-hooks\n            args:\n              - \"--hook\"\n              - \"\u003cid\u003e\" # follow 🎣 Hooks section to see available hooks IDs\n              - \"...\" # rest of args what you'd like to set (optional)\n            language: system\n    ```\n\n    Example:\n\n    ```yaml\n    default_install_hook_types:\n      - pre-commit\n      - prepare-commit-msg\n    repos:\n    - repo: local\n        hooks:\n        - id: chatgpt-commit-message\n          name: ChatGPT commit message\n          entry: chatgpt-pre-commit-hooks\n          args:\n            - \"--hook\"\n            - \"chatgpt-commit-message\"\n            - \"--description\"\n            - \"--emoji\"\n          language: system\n    ```\n\n## 🛠️ Advanced configuration\n\n### Extra environment variables\n\nIn addition to the environment variables listed in the [📥 Prerequisites setup](#-prerequisites-setup) section, you can set several configurations using extra environment variables.\n\n| Name                |  Type  |     Default     | Description                                                                                                                                  |\n|:--------------------|:------:|:---------------:|:---------------------------------------------------------------------------------------------------------------------------------------------|\n| `OPENAI_MAX_TOKENS` |  int   |      1024       | [What are tokens and how to count them?](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them)                  |\n| `OPENAI_MODEL`      | string | `gpt-3.5-turbo` | [Model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility) - check `/v1/chat/completions` endpoint |\n| `OPENAI_PROXY`      | string |    _not set_    | http/https client proxy                                                                                                                      |\n\n### Arguments\n\nAny environment variable can be overridden by hard-coded arguments in `pre-commit-config.yaml`, except `OPENAI_API_KEY`, `OPENAI_ORGANIZATION`.\n\n| Name                  |  Type  |  Default  | Description                                                                                                       |\n|:----------------------|:------:|:---------:|:------------------------------------------------------------------------------------------------------------------|\n| `--env-prefix`        | string | _not set_ | Set prefix for environment variables allowing multiple configurations. Read more: [`--env-prefix`](#--env-prefix) |\n| `--openai-max-tokens` |  int   | _not set_ | Overrides `OPENAI_MAX_TOKENS`                                                                                     |\n| `--openai-proxy`      | string | _not set_ | Overrides `OPENAI_PROXY`                                                                                          |\n| `--openai-model`      | string | _not set_ | Overrides `OPENAI_MODEL`                                                                                          |\n| `--openai-api-base`   | string | _not set_ | Overrides `OPENAI_API_BASE`                                                                                       |\n| `--openai-api-type`   | string | _not set_ | Overrides `OPENAI_API_TYPE`                                                                                       |\n\nExample:\n\n```yaml\ndefault_install_hook_types:\n  - pre-commit\n  - prepare-commit-msg\nrepos:\n  - repo: https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks\n    rev: vX.Y.Z\n    hooks:\n      - id: ... # follow 🎣 Hooks section to see available hooks IDs\n        args:\n          - \"--env-prefix\"\n          - \"personal\"\n          - \"--openai-max-tokens\"\n          - \"512\"\n          - ...\n```\n\n### `--env-prefix`\n\nIt's a special argument where you can mark prefixes for your environment variables. This allows you to set many configurations depending on the project, account, profile, etc., for example, `personal`, `work`. Fallback is a global environment variable if prefixed isn't found.\n\nFor instance, if your prefix is `personal`, then the environment variable must be set `PERSONAL__OPENAI_MAX_TOKENS`, meaning the structure is `\u003cprefix\u003e__\u003cbase_env_name\u003e` - two underscores `__` between `prefix` and `base_env_name`.\n\nExample:\n\n```shell\nexport PERSONAL__OPENAI_API_KEY=\"sk-xxxxxx\"\nexport WORK__OPENAI_API_KEY=\"sk-xxxxxx\"\n```\n\n### Variables precedence\n\n1. hard-coded arguments, for example `--openai-max-tokens`\n1. prefixed environment variable, for example `PERSONAL__OPENAI_MAX_TOKENS`\n1. global environment variable, for example `OPENAI_MAX_TOKENS`\n\n## 💸 Payments\n\nProject by default uses `gpt-3.5-turbo` model because of [its lower cost](https://openai.com/pricing). You have to pay for your own OpenAI API requests.\n\n## 👥 Contributing\n\nContributions to the project are welcome! Please follow [Contributing Guide](https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks/blob/main/CONTRIBUTING.md).\n\n## 📄 License\n\nThis project is distributed under the terms of the [MIT](https://opensource.org/licenses/MIT) license.\n\n[github-ci-image]: https://img.shields.io/github/actions/workflow/status/DariuszPorowski/chatgpt-pre-commit-hooks/workflow.ci.yml?style=flat-square\u0026branch=main\u0026event=push\n[github-ci-link]: https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks/actions/workflows/workflow.ci.yml?query=branch%3Amain+event%3Apush\n[pre-commit-image]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026style=flat-square\n[pre-commit-link]: https://github.com/pre-commit/pre-commit\n[pypi-version-image]: https://img.shields.io/pypi/v/chatgpt-pre-commit-hooks?style=flat-square\n[pypi-version-link]: https://pypi.org/project/chatgpt-pre-commit-hooks\n[pypi-pyversions-image]: https://img.shields.io/pypi/pyversions/chatgpt-pre-commit-hooks?style=flat-square\n[pypi-pyversions-link]: https://pypi.org/project/chatgpt-pre-commit-hooks\n[pypi-stats-image]: https://img.shields.io/pypi/dm/chatgpt-pre-commit-hooks?style=flat-square\n[pypi-stats-link]: https://pypistats.org/packages/chatgpt-pre-commit-hooks\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdariuszporowski%2Fchatgpt-pre-commit-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdariuszporowski%2Fchatgpt-pre-commit-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdariuszporowski%2Fchatgpt-pre-commit-hooks/lists"}