You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 21, 2025. It is now read-only.
✨ feat(scope): add pre-commit hooks and VSCode settings (#4)
## 💌 Description
📝 docs(scope): update chatgpt_commit_message documentation
This commit updates the `chatgpt_commit_message` documentation to
reflect recent changes and provide more detailed instructions on how to
use the tool. The `docs/chatgpt_commit_message.md` file has been updated
with additional examples and explanations.
📝 docs(scope): update README.md
This commit updates the `README.md` file to include more information
about the project and how to contribute. It also adds a section on
pre-commit hooks and how to set them up.
🐛 fix(scope): fix linting errors in chatgpt_commit_message.py
This commit fixes linting errors in the `chatgpt_commit_message.py`
file. The file now conforms to PEP8 standards and has improved
readability.
🔄 chore(scope): update dependencies in pyproject.toml
This commit updates the dependencies in the `pyproject.toml` file to
their latest versions.
## 🩹 Related issue
<!-- If your PR refers to a related issue, link it here. -->
Fixes: #
## 🏗️ Type of change
<!-- Mark with an `x` all the checkboxes that apply (like `[x]`) -->
- [ ] 📚 Examples / docs / tutorials / dependencies update
- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] 🥂 Improvement (non-breaking change which improves an existing
feature)
- [ ] 🚀 New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🔐 Security fix
- [ ] ⬆️ Dependencies update
## ✅ Checklist
<!-- Mark with an `x` all the checkboxes that apply (like `[x]`) -->
- [ ] I've read the
[`CODE_OF_CONDUCT.md`](https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks/blob/main/CODE_OF_CONDUCT.md)
document.
- [ ] I've read the
[`CONTRIBUTING.md`](https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks/blob/main/CONTRIBUTING.md)
guide.
- [ ] I've written tests for all new methods and classes that I created.
- [ ] I've written the docstring in Google format for all the methods
and classes that I used.
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.
34
+
35
+
- Read about hook's specific [configuration](https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks/blob/main/docs/chatgpt_commit_message.md).
36
+
37
+
## 📥 Prerequisites setup
38
+
39
+
Hooks support [OpenAI Platform](https://platform.openai.com) and [Azure OpenAI Service](https://azure.microsoft.com/products/cognitive-services/openai-service).
40
+
41
+
### OpenAI Platform
42
+
43
+
OpenAI API Key is mandatory to run hooks and has to be setup via an environment variable.
44
+
45
+
1. 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)
46
+
47
+

> How to setup env vars? see: [Setting environment variables](#setting-environment-variables)
65
+
66
+
### Azure OpenAI Service
67
+
68
+
1. Go to [Azure Portal](https://portal.azure.com), and get `API Key`, `Endpoint` and `Model deployment name`
69
+
70
+

> How to setup env vars? see: [Setting environment variables](#setting-environment-variables)
92
+
93
+
### Setting environment variables
94
+
95
+
Linux/MacOS example:
96
+
97
+
```shell
98
+
export OPENAI_API_KEY="sk-xxxxxx"
99
+
```
100
+
101
+
Windows `powershell` example:
102
+
103
+
```powershell
104
+
$env:OPENAI_API_KEY="sk-xxxxxx"
105
+
```
106
+
107
+
Windows `cmd` example:
108
+
109
+
```console
110
+
set OPENAI_API_KEY=sk-xxxxxx
111
+
```
112
+
113
+
> ⚠️ **NOTE**
114
+
>
115
+
> 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)
> 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)
56
162
57
-
#### Local repo reference
163
+
### Local repo reference
58
164
59
165
1. Install or add [PyPI](https://pypi.org/project/chatgpt-pre-commit-hooks) package to your project.
60
166
61
167
- if you are using [pip](https://pip.pypa.io):
62
168
63
169
```shell
64
-
pip install chatgpt-pre-commit-hooks
170
+
pip install --upgrade chatgpt-pre-commit-hooks
65
171
```
66
172
67
173
- or include it in a `requirements.txt` file in your project:
68
174
69
175
```text
70
-
chatgpt-pre-commit-hooks
176
+
chatgpt-pre-commit-hooks~=0.1.0
177
+
```
178
+
179
+
and run:
180
+
181
+
```shell
182
+
pip install -r requirements.txt
71
183
```
72
184
73
185
- or, even better, in the dev section of your `pyproject.toml` file:
@@ -77,13 +189,19 @@ repos:
77
189
dev = ["chatgpt-pre-commit-hooks"]
78
190
```
79
191
192
+
and run:
193
+
194
+
```shell
195
+
pip install .[dev]
196
+
```
197
+
80
198
- or, if you are using [poetry](https://python-poetry.org) as a package manager:
81
199
82
200
```shell
83
201
poetry add chatgpt-pre-commit-hooks --group dev
84
202
```
85
203
86
-
2. Add to your `.pre-commit-config.yaml`
204
+
1. Add to your `.pre-commit-config.yaml`
87
205
88
206
```yml
89
207
repos:
@@ -107,22 +225,66 @@ repos:
107
225
language: system
108
226
```
109
227
110
-
### OpenAI API Key
228
+
## 🛠️ Advanced configuration
111
229
112
-
Hooks require OpenAI access.
230
+
### Extra environment variables
113
231
114
-
1. Create your [OpenAI API Key](https://platform.openai.com/account/api-keys)
115
-
1. Store API key as an environment variable (see: [Best Practices for API Key Safety](https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety))
232
+
In addition to the environment variables listed in the [📥 Prerequisites setup](#-prerequisites-setup) section, you can set several configurations using extra environment variables.
|`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) |
- id: ... # follow 🎣 Hooks section to see available hooks IDs
261
+
args:
262
+
- "--env-prefix"
263
+
- "personal"
264
+
- "--openai-max-tokens"
265
+
- "512"
266
+
- ...
267
+
```
268
+
269
+
### `--env-prefix`
270
+
271
+
It's a special arg 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 is not found.
272
+
273
+
For instance, if your prefix is `personal`, then the environment variable must be set `PERSONAL__OPENAI_MAX_TOKENS`, meaning the structure is `<prefix>__<base_env_name>` - two underscores `__` between `prefix` and `base_env_name`.
274
+
275
+
Example:
276
+
277
+
### Variables precedence
278
+
279
+
1. hard-coded args, e.g. `--openai-max-tokens`
280
+
1. prefixed environment variable, e.g. `PERSONAL__OPENAI_MAX_TOKENS`
281
+
1. global environment variable, e.g. `OPENAI_MAX_TOKENS`
282
+
283
+
## 👥 Contributing
122
284
123
-
- Read [setup and usage](https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks/blob/main/docs/chatgpt_commit_message.md) for this hook.
285
+
Contributions to the project are very welcome! Please follow [Contributing Guide](https://github.com/DariuszPorowski/chatgpt-pre-commit-hooks/blob/main/CONTRIBUTING.md).
124
286
125
-
## License
287
+
## 📄 License
126
288
127
289
This project is distributed under the terms of the [MIT](https://opensource.org/licenses/MIT) license.
0 commit comments