commitai 0.1.16__tar.gz → 1.0.5__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.
- commitai-1.0.5/.github/workflows/main.yml +95 -0
- commitai-1.0.5/.gitignore +43 -0
- commitai-1.0.5/.pre-commit-config.yaml +40 -0
- commitai-1.0.5/LICENSE +22 -0
- commitai-1.0.5/PKG-INFO +316 -0
- commitai-1.0.5/README.md +255 -0
- commitai-1.0.5/assets/commitaai.gif +0 -0
- commitai-1.0.5/bitmap.png +0 -0
- commitai-1.0.5/commitai/__init__.py +10 -0
- commitai-1.0.5/commitai/cli.py +321 -0
- {commitai-0.1.16 → commitai-1.0.5}/commitai/template.py +3 -3
- commitai-1.0.5/pyproject.toml +126 -0
- commitai-1.0.5/tests/test_cli.py +565 -0
- commitai-1.0.5/tests/test_git.py +119 -0
- commitai-1.0.5/tests/test_template.py +45 -0
- commitai-0.1.16/PKG-INFO +0 -119
- commitai-0.1.16/README.md +0 -91
- commitai-0.1.16/commitai/__init__.py +0 -0
- commitai-0.1.16/commitai/cli.py +0 -187
- commitai-0.1.16/commitai.egg-info/PKG-INFO +0 -119
- commitai-0.1.16/commitai.egg-info/SOURCES.txt +0 -12
- commitai-0.1.16/commitai.egg-info/dependency_links.txt +0 -1
- commitai-0.1.16/commitai.egg-info/entry_points.txt +0 -3
- commitai-0.1.16/commitai.egg-info/requires.txt +0 -6
- commitai-0.1.16/commitai.egg-info/top_level.txt +0 -1
- commitai-0.1.16/setup.cfg +0 -4
- commitai-0.1.16/setup.py +0 -48
- {commitai-0.1.16 → commitai-1.0.5}/commitai/git.py +0 -0
|
@@ -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.5/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.
|
commitai-1.0.5/PKG-INFO
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: commitai
|
|
3
|
+
Version: 1.0.5
|
|
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.12,>=0.1.0
|
|
46
|
+
Requires-Dist: langchain-community<=0.3.23,>=0.0.20
|
|
47
|
+
Requires-Dist: langchain-core<=0.3.58,>=0.1.0
|
|
48
|
+
Requires-Dist: langchain-google-genai~=2.1.4
|
|
49
|
+
Requires-Dist: langchain-ollama~=0.3.2
|
|
50
|
+
Requires-Dist: langchain-openai<=0.3.16,>=0.1.0
|
|
51
|
+
Requires-Dist: langchain<=0.3.25,>=0.1.0
|
|
52
|
+
Requires-Dist: pydantic<3.0,>=2.0
|
|
53
|
+
Provides-Extra: test
|
|
54
|
+
Requires-Dist: langchain-google-genai~=2.1.4; extra == 'test'
|
|
55
|
+
Requires-Dist: mypy>=1.9.0; extra == 'test'
|
|
56
|
+
Requires-Dist: pytest-cov>=3.0; extra == 'test'
|
|
57
|
+
Requires-Dist: pytest>=7.0; extra == 'test'
|
|
58
|
+
Requires-Dist: ruff==0.4.4; extra == 'test'
|
|
59
|
+
Requires-Dist: types-setuptools; extra == 'test'
|
|
60
|
+
Description-Content-Type: text/markdown
|
|
61
|
+
|
|
62
|
+
# CommitAi - Your AI-Powered Commit Assistant
|
|
63
|
+
|
|
64
|
+
[](https://github.com/lguibr/commitai/actions/workflows/main.yml)
|
|
65
|
+
[](https://codecov.io/gh/lguibr/commitai) <!-- Added Codecov Badge -->
|
|
66
|
+
[](https://pypi.org/project/CommitAi/)
|
|
67
|
+
[](https://pypi.org/project/CommitAi/)
|
|
68
|
+
[](https://github.com/lguibr/CommitAi/blob/main/LICENSE)
|
|
69
|
+
[](https://github.com/astral-sh/ruff)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
<img
|
|
73
|
+
src="https://raw.githubusercontent.com/lguibr/commitai/main/bitmap.png"
|
|
74
|
+
alt="screenshot"
|
|
75
|
+
width="400"
|
|
76
|
+
/>
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
**Tired of writing Git commit messages? Let AI do the heavy lifting!**
|
|
80
|
+
|
|
81
|
+
**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.
|
|
82
|
+
|
|
83
|
+
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!
|
|
84
|
+
|
|
85
|
+
## Table of Contents
|
|
86
|
+
|
|
87
|
+
- [CommitAi - Your AI-Powered Commit Assistant](#commitai---your-ai-powered-commit-assistant)
|
|
88
|
+
- [Table of Contents](#table-of-contents)
|
|
89
|
+
- [Features](#features)
|
|
90
|
+
- [Demo](#demo)
|
|
91
|
+
- [Installation](#installation)
|
|
92
|
+
- [Configuration](#configuration)
|
|
93
|
+
- [API Keys](#api-keys)
|
|
94
|
+
- [Commit Templates (Optional)](#commit-templates-optional)
|
|
95
|
+
- [Usage](#usage)
|
|
96
|
+
- [Basic Workflow](#basic-workflow)
|
|
97
|
+
- [Command-Line Options](#command-line-options)
|
|
98
|
+
- [Creating Repository Templates](#creating-repository-templates)
|
|
99
|
+
- [Examples](#examples)
|
|
100
|
+
- [Contributing](#contributing)
|
|
101
|
+
- [License](#license)
|
|
102
|
+
|
|
103
|
+
## Features
|
|
104
|
+
|
|
105
|
+
* 🧠 **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.
|
|
106
|
+
* 📄 **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.
|
|
107
|
+
* 📝 **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.
|
|
108
|
+
* ✅ **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.
|
|
109
|
+
* 🔧 **Customizable Prompts via Templates**: Add custom instructions or context to the AI prompt using global environment variables or repository-specific template files.
|
|
110
|
+
* 🤖 **Multiple AI Provider Support**: Choose your preferred AI model from OpenAI, Anthropic, Google or local AI models with Ollama.
|
|
111
|
+
* ⚙️ **Flexible Workflow**:
|
|
112
|
+
* Stages all changes automatically (`-a` flag).
|
|
113
|
+
* Reviews message in your default Git editor (default behavior).
|
|
114
|
+
* Commits directly without editor review (`-c` flag).
|
|
115
|
+
* ✨ **Modern Tooling**: Built with `pyproject.toml` and formatted/linted with `ruff`.
|
|
116
|
+
|
|
117
|
+
## Demo
|
|
118
|
+
|
|
119
|
+

|
|
120
|
+
|
|
121
|
+
*(Demo shows generating a commit message using Claude 3 Opus without providing an explicit explanation)*
|
|
122
|
+
|
|
123
|
+
## Installation
|
|
124
|
+
|
|
125
|
+
Ensure you have Python 3.8+ and Git installed.
|
|
126
|
+
|
|
127
|
+
Install **CommitAi** directly from PyPI:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pip install commitai
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Configuration
|
|
134
|
+
|
|
135
|
+
### API Keys
|
|
136
|
+
|
|
137
|
+
CommitAi requires API keys for the AI provider you intend to use. Set these as environment variables:
|
|
138
|
+
|
|
139
|
+
* **OpenAI (GPT models):**
|
|
140
|
+
```bash
|
|
141
|
+
export OPENAI_API_KEY="your_openai_api_key_here"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
* **Anthropic (Claude models):**
|
|
145
|
+
```bash
|
|
146
|
+
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
* **Google (Gemini models):**
|
|
150
|
+
Set **one** of the following (CommitAi checks in this priority order):
|
|
151
|
+
1. `GOOGLE_API_KEY` (Recommended)
|
|
152
|
+
2. `GEMINI_API_KEY`
|
|
153
|
+
3. `GOOGLE_GENERATIVE_AI_API_KEY`
|
|
154
|
+
|
|
155
|
+
Example:
|
|
156
|
+
```bash
|
|
157
|
+
export GOOGLE_API_KEY="your_google_api_key_here"
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
You only need to set the key for the provider corresponding to the model you select (or the default, Gemini).
|
|
161
|
+
|
|
162
|
+
### Ollama
|
|
163
|
+
|
|
164
|
+
CommitAi can also work with Ollama models:
|
|
165
|
+
```bash
|
|
166
|
+
export OLLAMA_HOST="your_ollama_base_url"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
### Commit Templates (Optional)
|
|
171
|
+
|
|
172
|
+
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).
|
|
173
|
+
|
|
174
|
+
* **Global Template:** Set an environment variable. This applies to all repositories unless overridden locally.
|
|
175
|
+
```bash
|
|
176
|
+
# Example: Always ask the AI to reference a JIRA ticket format
|
|
177
|
+
export TEMPLATE_COMMIT="Ensure the commit footer includes a JIRA reference like 'Refs: PROJECT-123'."
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
* **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.
|
|
181
|
+
```bash
|
|
182
|
+
# Example: Instruct the AI to focus on UI changes for this specific repo
|
|
183
|
+
commitai-create-template "Focus the commit message body on user-facing UI changes."
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Note:** These templates *add* to the default system prompt, which already instructs the AI to follow Conventional Commits format. You are providing supplementary instructions.
|
|
187
|
+
|
|
188
|
+
## Usage
|
|
189
|
+
|
|
190
|
+
### Basic Workflow
|
|
191
|
+
|
|
192
|
+
1. **Make your code changes.**
|
|
193
|
+
2. **Stage the changes** you want to include in the commit:
|
|
194
|
+
```bash
|
|
195
|
+
git add <file1> <file2> ...
|
|
196
|
+
# or stage all changes in tracked files
|
|
197
|
+
git add .
|
|
198
|
+
# or stage all changes including untracked files
|
|
199
|
+
git add --all
|
|
200
|
+
```
|
|
201
|
+
3. **Run `commitai`:**
|
|
202
|
+
```bash
|
|
203
|
+
# Option 1: Let CommitAi infer the message from the diff
|
|
204
|
+
commitai
|
|
205
|
+
|
|
206
|
+
# Option 2: Provide a high-level explanation to guide the AI
|
|
207
|
+
commitai "Refactor user authentication to use JWT tokens"
|
|
208
|
+
```
|
|
209
|
+
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.
|
|
210
|
+
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.
|
|
211
|
+
|
|
212
|
+
### Command-Line Options
|
|
213
|
+
|
|
214
|
+
The `commitai` command (which is an alias for `commitai generate`) accepts the following options:
|
|
215
|
+
|
|
216
|
+
* `-a`, `--add`:
|
|
217
|
+
* Automatically stages *all* unstaged changes (`git add --all`) before generating the commit message.
|
|
218
|
+
* Useful for quickly committing everything in the working directory.
|
|
219
|
+
* Example: `commitai -a "Implement user profile page"`
|
|
220
|
+
|
|
221
|
+
* `-c`, `--commit`:
|
|
222
|
+
* Skips opening the Git editor for review. The generated message is used to create the commit directly.
|
|
223
|
+
* **Use with caution!** Reviewing AI-generated messages is recommended.
|
|
224
|
+
* Example: `commitai -c "Fix typo in documentation"` (for minor changes)
|
|
225
|
+
* Can be combined with `-a`: `commitai -a -c "Quick fix and commit all"`
|
|
226
|
+
|
|
227
|
+
* `-m <model_name>`, `--model <model_name>`:
|
|
228
|
+
* Specifies which AI model to use.
|
|
229
|
+
* Defaults to `gemini-2.5-pro-preview-03-25`.
|
|
230
|
+
* Ensure the corresponding API key environment variable is set.
|
|
231
|
+
* Examples:
|
|
232
|
+
* `commitai -m gpt-4 "Use OpenAI's GPT-4"`
|
|
233
|
+
* `commitai -m claude-3-opus-20240229 "Use Anthropic's Claude 3 Opus"`
|
|
234
|
+
* `commitai -m gemini-2.5-flash-preview-04-17 "Use Google's Gemini 1.5 Flash"`
|
|
235
|
+
|
|
236
|
+
### Creating Repository Templates
|
|
237
|
+
|
|
238
|
+
The `commitai-create-template` command sets a repository-specific template instruction.
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
commitai-create-template "Add a 'Co-authored-by:' line if applicable."
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
This creates/overwrites the `.git/commit_template.txt` file in the current repository.
|
|
245
|
+
|
|
246
|
+
## Examples
|
|
247
|
+
|
|
248
|
+
**1. Simple commit, inferred message:**
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# Stage changes
|
|
252
|
+
git add src/utils.py tests/test_utils.py
|
|
253
|
+
|
|
254
|
+
# Run commitai - AI infers message from diff
|
|
255
|
+
commitai
|
|
256
|
+
```
|
|
257
|
+
*(Editor opens with a message like `feat(utils): add helper function for data validation`)*
|
|
258
|
+
|
|
259
|
+
**2. Commit with explanation:**
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
# Stage changes
|
|
263
|
+
git add src/auth.py
|
|
264
|
+
|
|
265
|
+
# Run commitai with explanation
|
|
266
|
+
commitai "Implement password reset functionality using email tokens"
|
|
267
|
+
```
|
|
268
|
+
*(Editor opens with a message like `feat(auth): implement password reset via email token`)*
|
|
269
|
+
|
|
270
|
+
**3. Stage all and commit directly (no editor):**
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# Stage all changes and commit immediately using GPT-4
|
|
274
|
+
commitai -a -c -m gpt-4 "Minor refactoring and cleanup"
|
|
275
|
+
```
|
|
276
|
+
*(Commit is created directly)*
|
|
277
|
+
|
|
278
|
+
**4. Using a Template:**
|
|
279
|
+
|
|
280
|
+
* First, set a template:
|
|
281
|
+
```bash
|
|
282
|
+
commitai-create-template "Mention the related issue number from GitHub, e.g., Fixes #123."
|
|
283
|
+
```
|
|
284
|
+
* Then, run commitai:
|
|
285
|
+
```bash
|
|
286
|
+
git add src/parser.py
|
|
287
|
+
commitai "Fix bug in CSV parsing logic"
|
|
288
|
+
```
|
|
289
|
+
*(Editor opens with a message potentially like `fix(parser): correct handling of quoted commas\n\nFixes #123`)*
|
|
290
|
+
|
|
291
|
+
## Contributing
|
|
292
|
+
|
|
293
|
+
Contributions are highly welcome! Please follow these steps:
|
|
294
|
+
|
|
295
|
+
1. Fork the repository on GitHub.
|
|
296
|
+
2. Clone your fork locally: `git clone <your-fork-url>`
|
|
297
|
+
3. Navigate to the project directory: `cd commitai`
|
|
298
|
+
4. Create a virtual environment: `python -m venv .venv && source .venv/bin/activate` (or `.\.venv\Scripts\activate` on Windows)
|
|
299
|
+
5. Install dependencies, including development tools: `pip install -e ".[test]"`
|
|
300
|
+
6. **(Optional but Recommended)** Set up pre-commit hooks: `pre-commit install`
|
|
301
|
+
7. Create a new branch for your feature or bug fix: `git checkout -b my-feature-branch`
|
|
302
|
+
8. Make your changes.
|
|
303
|
+
9. Run checks locally before committing:
|
|
304
|
+
* Format code: `ruff format .`
|
|
305
|
+
* Lint code: `ruff check .`
|
|
306
|
+
* Run type checks: `mypy commitai tests`
|
|
307
|
+
* Run tests: `pytest`
|
|
308
|
+
10. Commit your changes (you can use `commitai`!).
|
|
309
|
+
11. Push your branch to your fork: `git push origin my-feature-branch`
|
|
310
|
+
12. Open a pull request on the main `lguibr/commitai` repository.
|
|
311
|
+
|
|
312
|
+
The CI pipeline will automatically run all checks on your pull request.
|
|
313
|
+
|
|
314
|
+
## License
|
|
315
|
+
|
|
316
|
+
**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.
|