commitai 0.1.15__tar.gz → 1.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,95 @@
1
+ # File: .github/workflows/main.yml
2
+ name: CI and Publish
3
+
4
+ on:
5
+ push:
6
+ branches: [ "main" ]
7
+ tags:
8
+ - 'v*'
9
+ pull_request:
10
+ branches: [ "main" ]
11
+
12
+ jobs:
13
+ test_and_lint:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ python-version: ["3.9", "3.11", "3.12"]
19
+
20
+ steps:
21
+ - name: Check out code
22
+ uses: actions/checkout@v4
23
+
24
+ - name: Set up Python ${{ matrix.python-version }}
25
+ uses: actions/setup-python@v5
26
+ with:
27
+ python-version: ${{ matrix.python-version }}
28
+ cache: 'pip'
29
+
30
+ - name: Install dependencies (including test extras)
31
+ run: |
32
+ python -m pip install --upgrade pip
33
+ pip install .[test]
34
+
35
+ - name: Lint and Format Check with Ruff
36
+ run: |
37
+ ruff format --check .
38
+ ruff check .
39
+
40
+ - name: Analyse code with Mypy
41
+ run: |
42
+ mypy commitai tests
43
+
44
+ - name: Run tests via Coverage
45
+ run: |
46
+ coverage run --rcfile=pyproject.toml -m pytest tests/
47
+
48
+ - name: Generate Coverage Report (XML)
49
+ run: |
50
+ coverage xml -o coverage.xml
51
+
52
+ - name: Check Coverage Threshold
53
+ run: |
54
+ # Extract the real fail_under value (ignore comments) and enforce it
55
+ FAIL_UNDER=$(grep -E '^\s*fail_under\s*=' pyproject.toml \
56
+ | sed 's/.*= *//')
57
+ coverage report --rcfile=pyproject.toml --fail-under=$FAIL_UNDER
58
+
59
+ - name: Upload coverage reports to Codecov
60
+ uses: codecov/codecov-action@v4
61
+ with:
62
+ token: ${{ secrets.CODECOV_TOKEN }}
63
+ slug: lguibr/commitai
64
+ files: ./coverage.xml
65
+ fail_ci_if_error: true
66
+
67
+ publish:
68
+ if: startsWith(github.ref, 'refs/tags/v')
69
+ needs: test_and_lint
70
+ runs-on: ubuntu-latest
71
+ permissions:
72
+ id-token: write
73
+
74
+ steps:
75
+ - name: Check out code
76
+ uses: actions/checkout@v4
77
+
78
+ - name: Set up Python for publishing
79
+ uses: actions/setup-python@v5
80
+ with:
81
+ python-version: '3.11'
82
+
83
+ - name: Install build dependencies
84
+ run: |
85
+ python -m pip install --upgrade pip
86
+ pip install build twine
87
+
88
+ - name: Build package
89
+ run: python -m build
90
+
91
+ - name: Publish package to PyPI
92
+ # Twine will automatically use the OIDC token provided by the runner environment
93
+ # when run in a job with 'id-token: write' permissions.
94
+ # Ensure you have configured Trusted Publishing on PyPI for this repo/workflow.
95
+ run: twine upload dist/*
@@ -0,0 +1,43 @@
1
+
2
+ # Byte-compiled / optimized / DLL files
3
+ __pycache__/
4
+ *.py[cod]
5
+ *$py.class
6
+
7
+ # Distribution / packaging
8
+ dist/
9
+ build/
10
+ *.egg-info/
11
+ *.egg
12
+ wheels/
13
+ *.whl
14
+
15
+ # Virtual environments
16
+ venv/
17
+ .venv/
18
+ env/
19
+ .env
20
+
21
+ # IDE files
22
+ .vscode/
23
+ .idea/
24
+
25
+ # Miscellaneous
26
+ *.log
27
+ *.swp
28
+ *.swo
29
+ *.bak
30
+ .DS_Store
31
+
32
+ # Tool Caches
33
+ .mypy_cache/
34
+ .pytest_cache/
35
+ .ruff_cache/
36
+
37
+ # Coverage
38
+ .coverage
39
+ coverage.xml
40
+ htmlcov/
41
+
42
+ # Build artifacts
43
+ commitai.egg-info/
@@ -0,0 +1,40 @@
1
+ # File: .pre-commit-config.yaml
2
+ # See https://pre-commit.com for more information
3
+ # See https://pre-commit.com/hooks.html for more hooks
4
+ repos:
5
+ - repo: https://github.com/pre-commit/pre-commit-hooks
6
+ rev: v4.6.0 # Use a recent version
7
+ hooks:
8
+ - id: check-yaml
9
+ - id: end-of-file-fixer
10
+ - id: trailing-whitespace
11
+ - id: check-added-large-files
12
+
13
+ - repo: https://github.com/astral-sh/ruff-pre-commit
14
+ # Ruff version. Must be aligned with the version in pyproject.toml
15
+ rev: v0.4.4 # Choose a specific Ruff version
16
+ hooks:
17
+ # Run the linter. Applies fixes including import sorting, etc.
18
+ - id: ruff
19
+ args: [--fix, --exit-non-zero-on-fix] # Auto-fix and fail if fixes were made
20
+ # Run the formatter. Ensures final code style consistency.
21
+ - id: ruff-format
22
+
23
+ - repo: https://github.com/pre-commit/mirrors-mypy
24
+ rev: v1.10.0 # Use a recent version of mypy mirror
25
+ hooks:
26
+ - id: mypy
27
+ # Ensure mypy runs with the necessary dependencies installed
28
+ additional_dependencies: [
29
+ "click>=8.0,<9.0",
30
+ "langchain>=0.1.0,<0.3.0",
31
+ "langchain-community>=0.0.20,<0.2.0",
32
+ "langchain-anthropic>=0.1.0,<0.3.0",
33
+ "langchain-openai>=0.1.0,<0.3.0",
34
+ "langchain-google-genai~=0.0.9",
35
+ "pydantic>=2.0,<3.0",
36
+ "types-setuptools"
37
+ ]
38
+ args: [--config-file=pyproject.toml] # Point mypy to the config
39
+ # You might need to adjust entry if your structure changes
40
+ # entry: mypy commitai commitai/tests
commitai-1.0.4/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ # File: LICENSE
2
+ MIT License
3
+
4
+ Copyright (c) 2024 Luis Guilherme
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,303 @@
1
+ Metadata-Version: 2.4
2
+ Name: commitai
3
+ Version: 1.0.4
4
+ Summary: Commitai helps you generate git commit messages using AI
5
+ Project-URL: Bug Tracker, https://github.com/lguibr/commitai/issues
6
+ Project-URL: Documentation, https://github.com/lguibr/commitai/blob/main/README.md
7
+ Project-URL: Source Code, https://github.com/lguibr/commitai
8
+ Author-email: Luis Guilherme <lgpelin92@gmail.com>
9
+ License: # File: LICENSE
10
+ MIT License
11
+
12
+ Copyright (c) 2024 Luis Guilherme
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENSE
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Programming Language :: Python :: 3
37
+ Classifier: Programming Language :: Python :: 3.9
38
+ Classifier: Programming Language :: Python :: 3.10
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: Programming Language :: Python :: 3.12
41
+ Classifier: Topic :: Software Development :: Version Control :: Git
42
+ Classifier: Topic :: Utilities
43
+ Requires-Python: >=3.9
44
+ Requires-Dist: click<9.0,>=8.0
45
+ Requires-Dist: langchain-anthropic<0.3.0,>=0.1.0
46
+ Requires-Dist: langchain-community<0.2.0,>=0.0.20
47
+ Requires-Dist: langchain-core<0.3.0,>=0.1.0
48
+ Requires-Dist: langchain-google-genai~=0.0.9
49
+ Requires-Dist: langchain-openai<0.3.0,>=0.1.0
50
+ Requires-Dist: langchain<0.3.0,>=0.1.0
51
+ Requires-Dist: pydantic<3.0,>=2.0
52
+ Provides-Extra: test
53
+ Requires-Dist: langchain-google-genai~=0.0.9; extra == 'test'
54
+ Requires-Dist: mypy>=1.9.0; extra == 'test'
55
+ Requires-Dist: pytest-cov>=3.0; extra == 'test'
56
+ Requires-Dist: pytest>=7.0; extra == 'test'
57
+ Requires-Dist: ruff==0.4.4; extra == 'test'
58
+ Requires-Dist: types-setuptools; extra == 'test'
59
+ Description-Content-Type: text/markdown
60
+
61
+ # CommitAi - Your AI-Powered Commit Assistant
62
+
63
+ [![CI and Publish](https://github.com/lguibr/commitai/actions/workflows/main.yml/badge.svg)](https://github.com/lguibr/commitai/actions/workflows/main.yml)
64
+ [![codecov](https://codecov.io/gh/lguibr/commitai/graph/badge.svg?token=MXZKCXO6LA)](https://codecov.io/gh/lguibr/commitai) <!-- Added Codecov Badge -->
65
+ [![PyPI](https://img.shields.io/pypi/v/CommitAi.svg)](https://pypi.org/project/CommitAi/)
66
+ [![Python Version](https://img.shields.io/pypi/pyversions/CommitAi.svg)](https://pypi.org/project/CommitAi/)
67
+ [![License](https://img.shields.io/pypi/l/CommitAi.svg)](https://github.com/lguibr/CommitAi/blob/main/LICENSE)
68
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
69
+
70
+ <p align="center">
71
+ <img src="bitmap.png" alt="Logo" width="300"/>
72
+ </p>
73
+
74
+ **Tired of writing Git commit messages? Let AI do the heavy lifting!**
75
+
76
+ **CommitAi** streamlines your Git workflow by leveraging powerful AI models (OpenAI's GPT, Anthropic's Claude, Google's Gemini) to automatically generate clear, concise, and conventional commit messages based on your staged changes.
77
+
78
+ Simply stage your files and run `commitai`. It analyzes the diff, optionally takes your high-level explanation, and crafts a commit message adhering to the [Conventional Commits](https://www.conventionalcommits.org/) standard. Review the message in your default Git editor, make any tweaks, save, and you're done!
79
+
80
+ ## Table of Contents
81
+
82
+ - [CommitAi - Your AI-Powered Commit Assistant](#commitai---your-ai-powered-commit-assistant)
83
+ - [Table of Contents](#table-of-contents)
84
+ - [Features](#features)
85
+ - [Demo](#demo)
86
+ - [Installation](#installation)
87
+ - [Configuration](#configuration)
88
+ - [API Keys](#api-keys)
89
+ - [Commit Templates (Optional)](#commit-templates-optional)
90
+ - [Usage](#usage)
91
+ - [Basic Workflow](#basic-workflow)
92
+ - [Command-Line Options](#command-line-options)
93
+ - [Creating Repository Templates](#creating-repository-templates)
94
+ - [Examples](#examples)
95
+ - [Contributing](#contributing)
96
+ - [License](#license)
97
+
98
+ ## Features
99
+
100
+ * 🧠 **Intelligent Commit Generation**: Analyzes staged code differences (`git diff --staged`) using state-of-the-art AI models (GPT, Claude, Gemini) to create meaningful commit messages.
101
+ * 📄 **Conventional Commits**: Automatically formats messages according to the Conventional Commits specification (e.g., `feat(auth): add JWT authentication`). This improves readability and enables automated changelog generation.
102
+ * 📝 **Optional Explanations**: Provide a high-level description of your changes as input to guide the AI, or let it infer the context solely from the code diff.
103
+ * ✅ **Pre-commit Hook Integration**: Automatically runs your existing native Git pre-commit hook (`.git/hooks/pre-commit`) before generating the message, ensuring code quality and style checks pass.
104
+ * 🔧 **Customizable Prompts via Templates**: Add custom instructions or context to the AI prompt using global environment variables or repository-specific template files.
105
+ * 🤖 **Multiple AI Provider Support**: Choose your preferred AI model from OpenAI, Anthropic, or Google.
106
+ * ⚙️ **Flexible Workflow**:
107
+ * Stages all changes automatically (`-a` flag).
108
+ * Reviews message in your default Git editor (default behavior).
109
+ * Commits directly without editor review (`-c` flag).
110
+ * ✨ **Modern Tooling**: Built with `pyproject.toml` and formatted/linted with `ruff`.
111
+
112
+ ## Demo
113
+
114
+ ![CommitAi Demo](./assets/commitaai.gif)
115
+
116
+ *(Demo shows generating a commit message using Claude 3 Opus without providing an explicit explanation)*
117
+
118
+ ## Installation
119
+
120
+ Ensure you have Python 3.8+ and Git installed.
121
+
122
+ Install **CommitAi** directly from PyPI:
123
+
124
+ ```bash
125
+ pip install commitai
126
+ ```
127
+
128
+ ## Configuration
129
+
130
+ ### API Keys
131
+
132
+ CommitAi requires API keys for the AI provider you intend to use. Set these as environment variables:
133
+
134
+ * **OpenAI (GPT models):**
135
+ ```bash
136
+ export OPENAI_API_KEY="your_openai_api_key_here"
137
+ ```
138
+
139
+ * **Anthropic (Claude models):**
140
+ ```bash
141
+ export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
142
+ ```
143
+
144
+ * **Google (Gemini models):**
145
+ Set **one** of the following (CommitAi checks in this priority order):
146
+ 1. `GOOGLE_API_KEY` (Recommended)
147
+ 2. `GEMINI_API_KEY`
148
+ 3. `GOOGLE_GENERATIVE_AI_API_KEY`
149
+
150
+ Example:
151
+ ```bash
152
+ export GOOGLE_API_KEY="your_google_api_key_here"
153
+ ```
154
+
155
+ You only need to set the key for the provider corresponding to the model you select (or the default, Gemini).
156
+
157
+ ### Commit Templates (Optional)
158
+
159
+ You can add custom instructions to the default system prompt used by the AI. This is useful for enforcing project-specific guidelines (e.g., mentioning ticket numbers).
160
+
161
+ * **Global Template:** Set an environment variable. This applies to all repositories unless overridden locally.
162
+ ```bash
163
+ # Example: Always ask the AI to reference a JIRA ticket format
164
+ export TEMPLATE_COMMIT="Ensure the commit footer includes a JIRA reference like 'Refs: PROJECT-123'."
165
+ ```
166
+
167
+ * **Repository-Specific Template:** Use the `commitai-create-template` command within your repository. This creates a `.git/commit_template.txt` file and overrides the global `TEMPLATE_COMMIT` variable for this repo only.
168
+ ```bash
169
+ # Example: Instruct the AI to focus on UI changes for this specific repo
170
+ commitai-create-template "Focus the commit message body on user-facing UI changes."
171
+ ```
172
+
173
+ **Note:** These templates *add* to the default system prompt, which already instructs the AI to follow Conventional Commits format. You are providing supplementary instructions.
174
+
175
+ ## Usage
176
+
177
+ ### Basic Workflow
178
+
179
+ 1. **Make your code changes.**
180
+ 2. **Stage the changes** you want to include in the commit:
181
+ ```bash
182
+ git add <file1> <file2> ...
183
+ # or stage all changes in tracked files
184
+ git add .
185
+ # or stage all changes including untracked files
186
+ git add --all
187
+ ```
188
+ 3. **Run `commitai`:**
189
+ ```bash
190
+ # Option 1: Let CommitAi infer the message from the diff
191
+ commitai
192
+
193
+ # Option 2: Provide a high-level explanation to guide the AI
194
+ commitai "Refactor user authentication to use JWT tokens"
195
+ ```
196
+ 4. **Review & Edit:** CommitAi runs pre-commit hooks, generates the message, and opens it in your default Git editor (e.g., Vim, Nano, VS Code). Review the message, make any necessary edits.
197
+ 5. **Save & Close:** Save the file and close the editor. CommitAi will then create the commit with the final message. If you close without saving or clear the message, the commit will be aborted.
198
+
199
+ ### Command-Line Options
200
+
201
+ The `commitai` command (which is an alias for `commitai generate`) accepts the following options:
202
+
203
+ * `-a`, `--add`:
204
+ * Automatically stages *all* unstaged changes (`git add --all`) before generating the commit message.
205
+ * Useful for quickly committing everything in the working directory.
206
+ * Example: `commitai -a "Implement user profile page"`
207
+
208
+ * `-c`, `--commit`:
209
+ * Skips opening the Git editor for review. The generated message is used to create the commit directly.
210
+ * **Use with caution!** Reviewing AI-generated messages is recommended.
211
+ * Example: `commitai -c "Fix typo in documentation"` (for minor changes)
212
+ * Can be combined with `-a`: `commitai -a -c "Quick fix and commit all"`
213
+
214
+ * `-m <model_name>`, `--model <model_name>`:
215
+ * Specifies which AI model to use.
216
+ * Defaults to `gemini-2.5-pro-preview-03-25`.
217
+ * Ensure the corresponding API key environment variable is set.
218
+ * Examples:
219
+ * `commitai -m gpt-4 "Use OpenAI's GPT-4"`
220
+ * `commitai -m claude-3-opus-20240229 "Use Anthropic's Claude 3 Opus"`
221
+ * `commitai -m gemini-2.5-flash-preview-04-17 "Use Google's Gemini 1.5 Flash"`
222
+
223
+ ### Creating Repository Templates
224
+
225
+ The `commitai-create-template` command sets a repository-specific template instruction.
226
+
227
+ ```bash
228
+ commitai-create-template "Add a 'Co-authored-by:' line if applicable."
229
+ ```
230
+
231
+ This creates/overwrites the `.git/commit_template.txt` file in the current repository.
232
+
233
+ ## Examples
234
+
235
+ **1. Simple commit, inferred message:**
236
+
237
+ ```bash
238
+ # Stage changes
239
+ git add src/utils.py tests/test_utils.py
240
+
241
+ # Run commitai - AI infers message from diff
242
+ commitai
243
+ ```
244
+ *(Editor opens with a message like `feat(utils): add helper function for data validation`)*
245
+
246
+ **2. Commit with explanation:**
247
+
248
+ ```bash
249
+ # Stage changes
250
+ git add src/auth.py
251
+
252
+ # Run commitai with explanation
253
+ commitai "Implement password reset functionality using email tokens"
254
+ ```
255
+ *(Editor opens with a message like `feat(auth): implement password reset via email token`)*
256
+
257
+ **3. Stage all and commit directly (no editor):**
258
+
259
+ ```bash
260
+ # Stage all changes and commit immediately using GPT-4
261
+ commitai -a -c -m gpt-4 "Minor refactoring and cleanup"
262
+ ```
263
+ *(Commit is created directly)*
264
+
265
+ **4. Using a Template:**
266
+
267
+ * First, set a template:
268
+ ```bash
269
+ commitai-create-template "Mention the related issue number from GitHub, e.g., Fixes #123."
270
+ ```
271
+ * Then, run commitai:
272
+ ```bash
273
+ git add src/parser.py
274
+ commitai "Fix bug in CSV parsing logic"
275
+ ```
276
+ *(Editor opens with a message potentially like `fix(parser): correct handling of quoted commas\n\nFixes #123`)*
277
+
278
+ ## Contributing
279
+
280
+ Contributions are highly welcome! Please follow these steps:
281
+
282
+ 1. Fork the repository on GitHub.
283
+ 2. Clone your fork locally: `git clone <your-fork-url>`
284
+ 3. Navigate to the project directory: `cd commitai`
285
+ 4. Create a virtual environment: `python -m venv .venv && source .venv/bin/activate` (or `.\.venv\Scripts\activate` on Windows)
286
+ 5. Install dependencies, including development tools: `pip install -e ".[test]"`
287
+ 6. **(Optional but Recommended)** Set up pre-commit hooks: `pre-commit install`
288
+ 7. Create a new branch for your feature or bug fix: `git checkout -b my-feature-branch`
289
+ 8. Make your changes.
290
+ 9. Run checks locally before committing:
291
+ * Format code: `ruff format .`
292
+ * Lint code: `ruff check .`
293
+ * Run type checks: `mypy commitai commitai/tests`
294
+ * Run tests: `pytest`
295
+ 10. Commit your changes (you can use `commitai`!).
296
+ 11. Push your branch to your fork: `git push origin my-feature-branch`
297
+ 12. Open a pull request on the main `lguibr/commitai` repository.
298
+
299
+ The CI pipeline will automatically run all checks on your pull request.
300
+
301
+ ## License
302
+
303
+ **CommitAi** is open-source software licensed under the MIT License. See the [LICENSE](https://github.com/lguibr/CommitAi/blob/main/LICENSE) file for more details.