Skip to content

Commit 56549a6

Browse files
author
edgar-zorrilla-smartports
committed
Initial commit
0 parents  commit 56549a6

File tree

7 files changed

+1591
-0
lines changed

7 files changed

+1591
-0
lines changed

.gitignore

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.nox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*.cover
48+
.hypothesis/
49+
.pytest_cache/
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Environments
56+
.env
57+
.venv
58+
env/
59+
venv/
60+
ENV/
61+
env.bak/
62+
venv.bak/
63+
64+
# IDE specific files
65+
.idea/
66+
.vscode/
67+
*.swp
68+
*.swo
69+
*~
70+
71+
# macOS specific
72+
.DS_Store
73+
74+
# Log files
75+
*.log

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Edgar Zorrilla
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
# Smart Git Commit 🚀
2+
3+
An AI-powered Git workflow tool that intelligently analyzes your changes, groups them into logical commits, and generates detailed conventional commit messages.
4+
5+
## Features
6+
7+
- 🤖 **AI-Powered Analysis**: Leverages Ollama models to understand your code changes
8+
- 🔍 **Intelligent Grouping**: Organizes changes into logical, atomic commits
9+
- 📝 **Conventional Commits**: Generates structured commit messages following the convention
10+
- 🔄 **Tech Stack Detection**: Automatically adapts to different programming languages and frameworks
11+
- 🚀 **GPU Acceleration**: Uses hardware acceleration for faster processing
12+
-**Fallback Mechanism**: Works even without AI using rule-based analysis
13+
- 🎯 **Smart Change Importance**: Prioritizes changes based on impact analysis
14+
- 🧩 **Component Detection**: Identifies file components based on project structure
15+
16+
## Installation
17+
18+
```bash
19+
# Install from PyPI
20+
pip install smart-git-commit
21+
22+
# Or install directly from the repository
23+
pip install git+https://github.com/yourusername/smart-git-commit.git
24+
```
25+
26+
## Requirements
27+
28+
- Python 3.7+
29+
- Git
30+
- Ollama (optional, for AI-powered features)
31+
32+
## Usage
33+
34+
```bash
35+
# Basic usage (will prompt for Ollama model selection)
36+
smart-git-commit
37+
38+
# Disable AI-powered analysis
39+
smart-git-commit --no-ai
40+
41+
# Use a specific Ollama model
42+
smart-git-commit --ollama-model llama3
43+
44+
# Non-interactive mode
45+
smart-git-commit --non-interactive
46+
47+
# Specify a repository path
48+
smart-git-commit --repo-path /path/to/your/repository
49+
50+
# See all options
51+
smart-git-commit --help
52+
```
53+
54+
### Command Line Options
55+
56+
```
57+
usage: smart-git-commit [-h] [--repo-path REPO_PATH] [--non-interactive]
58+
[--ollama-host OLLAMA_HOST]
59+
[--ollama-model OLLAMA_MODEL] [--no-ai]
60+
61+
Smart Git Commit Workflow with Ollama Integration
62+
63+
options:
64+
-h, --help show this help message and exit
65+
--repo-path REPO_PATH
66+
Path to the git repository
67+
--non-interactive Run without interactive prompts
68+
--ollama-host OLLAMA_HOST
69+
Host for Ollama API
70+
--ollama-model OLLAMA_MODEL
71+
Model to use for Ollama (will prompt if not specified)
72+
--no-ai Disable AI-powered analysis
73+
```
74+
75+
## Example Commit
76+
77+
Here's an example of a commit message generated by Smart Git Commit:
78+
79+
```
80+
feat(api-auth): Add JWT token validation middleware
81+
82+
Implement secure JWT token validation with proper error handling and
83+
expiration checks. Add support for refresh tokens with configurable
84+
lifetime settings.
85+
86+
Affected files:
87+
- M src/auth/jwt_validator.js
88+
- M src/middleware/auth.js
89+
- + src/utils/token_helpers.js
90+
- M config/auth.json
91+
92+
Fixes #123
93+
```
94+
95+
## How It Works
96+
97+
### Workflow Overview
98+
99+
1. **Load Changes**: Detects all modified and untracked files in the Git repository
100+
2. **Analyze Changes**: Examines each file's content, language, and importance
101+
3. **Group Changes**: Organizes related files into logical, atomic commits
102+
4. **Generate Commit Messages**: Creates detailed, conventional commit messages
103+
5. **Execute Commits**: Handles the git staging and commit process
104+
105+
### Change Analysis
106+
107+
The tool analyzes changes through multiple dimensions:
108+
109+
- **File Status**: Checks if files are modified, added, or deleted
110+
- **Language Detection**: Identifies programming languages based on file extensions
111+
- **Component Recognition**: Maps files to logical components (e.g., docs, tests, api)
112+
- **Tech Stack Detection**: Detects project technologies (e.g., Python, Node.js, React)
113+
- **Importance Rating**: With AI, assesses the impact and significance of each change
114+
115+
### Intelligent Grouping
116+
117+
Changes are grouped based on:
118+
119+
- **Component Coherence**: Files from the same component are grouped together
120+
- **Logical Relationship**: AI analyzes file dependencies and relationships
121+
- **Change Size Management**: Large groups are split into smaller, coherent commits
122+
- **Commit Type Assignment**: Each group is assigned a conventional commit type (feat, fix, etc.)
123+
124+
### Ollama LLM Integration
125+
126+
When using AI mode (default):
127+
128+
1. Smart Git Commit connects to Ollama's API
129+
2. Available LLM models are detected automatically
130+
3. The selected model analyzes file changes and content
131+
4. AI determines logical groupings and generates commit descriptions
132+
5. GPU acceleration is used when available
133+
134+
### Non-AI Fallback
135+
136+
When AI is unavailable or disabled:
137+
138+
1. Files are grouped by component/directory
139+
2. Commit types are assigned based on file paths and extensions
140+
3. Basic commit messages are generated using rule-based templates
141+
4. The user can interactively refine the commit details
142+
143+
### Interactive Workflow
144+
145+
In interactive mode (default):
146+
147+
1. Each commit group is presented for review
148+
2. You can approve, skip, or edit the commit details
149+
3. Edit options include changing the commit name, type, description, and issue references
150+
4. The tool handles staging and committing the files
151+
5. You can review the final commit before proceeding to the next group
152+
153+
## Project Structure
154+
155+
- **`CommitType` Enum**: Defines conventional commit types (feat, fix, docs, etc.)
156+
- **`GitChange` Class**: Represents a changed file with metadata
157+
- **`CommitGroup` Class**: Groups related changes for a single commit
158+
- **`OllamaClient` Class**: Handles communication with Ollama API
159+
- **`SmartGitCommitWorkflow` Class**: Orchestrates the entire commit process
160+
161+
## Advanced Usage
162+
163+
### Using Custom Ollama Endpoints
164+
165+
```bash
166+
# Use a different Ollama host
167+
smart-git-commit --ollama-host http://custom-ollama-server:11434
168+
```
169+
170+
### Non-Interactive Automation
171+
172+
```bash
173+
# For CI/CD or automated scripts
174+
smart-git-commit --non-interactive
175+
```
176+
177+
### Working with Multiple Repositories
178+
179+
```bash
180+
# Specify the repository path
181+
smart-git-commit --repo-path /path/to/your/repository
182+
```
183+
184+
## Troubleshooting
185+
186+
### Ollama Connection Issues
187+
188+
If you encounter issues connecting to Ollama:
189+
190+
1. Ensure Ollama is running: `ollama serve`
191+
2. Check that you have at least one model: `ollama list`
192+
3. Try specifying the host explicitly: `--ollama-host http://localhost:11434`
193+
194+
### Falling Back to Non-AI Mode
195+
196+
If AI analysis isn't working properly:
197+
198+
```bash
199+
# Run with fallback mode explicitly
200+
smart-git-commit --no-ai
201+
```
202+
203+
## Contributing
204+
205+
Contributions are welcome! Please feel free to submit a Pull Request.
206+
207+
To set up your development environment:
208+
209+
1. Clone the repository
210+
2. Install development dependencies: `pip install -e ".[dev]"`
211+
3. Run tests: `pytest tests/`
212+
213+
## License
214+
215+
MIT
216+
217+
## Acknowledgements
218+
219+
- [Conventional Commits](https://www.conventionalcommits.org/) for the commit message format
220+
- [Ollama](https://github.com/ollama/ollama) for the local LLM capabilities

pyproject.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "smart-git-commit"
7+
version = "0.1.0"
8+
description = "AI-powered Git commit workflow tool"
9+
readme = "README.md"
10+
authors = [
11+
{name = "Your Name", email = "your.email@example.com"}
12+
]
13+
license = {text = "MIT"}
14+
classifiers = [
15+
"Development Status :: 4 - Beta",
16+
"Environment :: Console",
17+
"Intended Audience :: Developers",
18+
"License :: OSI Approved :: MIT License",
19+
"Operating System :: OS Independent",
20+
"Programming Language :: Python :: 3",
21+
"Programming Language :: Python :: 3.7",
22+
"Programming Language :: Python :: 3.8",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Topic :: Software Development :: Version Control :: Git",
26+
]
27+
requires-python = ">=3.7"
28+
dependencies = []
29+
30+
[project.urls]
31+
Homepage = "https://github.com/yourusername/smart-git-commit"
32+
Issues = "https://github.com/yourusername/smart-git-commit/issues"
33+
34+
[project.scripts]
35+
smart-git-commit = "smart_git_commit:main"
36+
37+
[tool.isort]
38+
profile = "black"
39+
line_length = 88
40+
41+
[tool.black]
42+
line-length = 88
43+
target-version = ["py37"]
44+
45+
[tool.ruff]
46+
line-length = 88
47+
target-version = "py37"
48+
select = ["E", "F", "I", "W"]

0 commit comments

Comments
 (0)