Automação de PRs, Commits e Code Review com IA (Gemini e DeepSeek)
Project description
GitPR CLI 🚀
GitPR CLI is a command-line automation tool that uses Google Gemini and DeepSeek artificial intelligence to analyze your code changes (git diff) or entire files. The tool automatically generates commit messages in the Conventional Commits standard, detailed Pull Request descriptions, and deep Code Reviews aimed at reducing technical debt.
🛠️ Technologies and Libraries Used
This project was developed in Python and uses the following main libraries:
- Click: To create a robust and user-friendly command-line interface (CLI).
- Google GenAI: Official SDK for direct integration with the Gemini API.
- OpenAI: Library used due to its full compatibility with the powerful DeepSeek API.
- Python-dotenv: For secure environment variable management.
- Pytest: For running unit tests in a simple, colorful, and readable way in the console.
- Cryptography: To ensure your
GEMINI_API_KEYis stored encrypted and securely on disk. - PyYAML: Used to read and process the custom static analysis rules from the
.gitpr.linter.ymlfile. - Textual: Powerful library for creating Terminal Graphical Interfaces (TUI), used in the interactive issue generation and editing panel.
- Requests: Elegant and robust library for HTTP requests, used to communicate with the GitHub REST API.
📦 How to Compile the Executable Locally
If you want to generate your own binary from the source code, we use PyInstaller. Make sure you are in the project root directory with the virtual environment configured.
-
Install development dependencies (if you haven't already):
pipenv install --dev
-
Run the build command pointing to our entry point (
run.py):pipenv run pyinstaller --noconfirm --onefile --icon=icon.ico --name gitpr run.py
Technical note: The
--onefileflag ensures all Python, libraries, and dependencies are compressed into a single binary, while--paths srchelps the compiler find ourcore.pyandconfig.pyfiles. 🛠️
After running this command, PyInstaller will create some folders (build and dist).
Your final ready-to-use file will be inside the dist/ folder named gitpr (or gitpr.exe on Windows).
🧪 Running Tests
To ensure the Git capture logic and AI integration are working correctly, we use unit tests.
-
Install test dependencies (if you haven't already):
pipenv install --dev pytest
-
Run the tests with the command:
pipenv run pytest -v
Pytest will automatically detect files inside the tests/ folder and display a detailed execution report.
⚙️ Installation and Configuration
Using the Executable (Recommended)
- Download the gitpr executable file from the "Releases" tab on GitHub.
- Move the executable to a folder that is in your PATH (e.g.: /usr/local/bin on Linux/Mac or your user folder on Windows).
- On the first run, the wizard will guide you:
$ gitpr
🚀 Intelligent PR Automation with AI
🔧 First run detected! Let's configure GitPR CLI.
🔑 Enter your GEMINI_API_KEY:
📄 Default output filename pattern [{branch}_{datetime}_PR_DESC.md]:
Note: Your configuration will be securely saved in the ~/.gitpr/.env file.
🔒 Security Note: GitPR CLI uses symmetric encryption (Fernet). Your API key is stored as a hash in the
.envfile, and the master key for decryption is automatically generated in~/.gitpr/secret.key. Never share your secret.key file.
From Source Code
-
Clone the repository:
git clone https://github.com/natanfiuza/gitpr.git -
Enter the folder:
cd gitpr -
Set up the environment:
pipenv install google-genai openai python-dotenv click cryptography
- Run: pipenv run python src/main.py
💻 How to Use
GitPR has a powerful default behavior and several advanced options to assist you in your day-to-day as a developer.
Default Behavior (Pull Request)
Simply run the bare command in your terminal:
gitpr
The tool will sync with the remote (git fetch), compare your changes with the remote main branch (e.g.: origin/main), and generate a Markdown file (e.g.: feature-login_20260421110134_PR_DESC.md) at the root of your project with the complete suggestion for your Pull Request.
Advanced Options and Commands
You can pass the following flags for specific actions:
-cor--commit: Runs a localgit diffand displays only the suggested commit message.-ror--review: Performs a detailed Code Review of local changes.-for--fullreview: Performs a Full Code Review analyzing all changes since the remote branch.-i <file>or--input <file>: Full File Audit. Must be used together with-ror-f; it ignores git history and does a Code Review of the entire file. Excellent for acting as a consultant on legacy code refactoring.--provider <gemini|deepseek>: Forces the use of a specific AI only for this execution, ignoring your default saved in.env.-lor--linter: Runs only the local static linter (no AI calls). Ideal for use in CI/CD pipelines to block non-compliant code.-ihor--installhooks: Automatically installs local Git Hooks (pre-commitandprepare-commit-msg) in your repository.-sor--skill: Creates the AI context template files (.gitpr.commit.md,.gitpr.pr.md,.gitpr.review.md,.gitpr.filereview.md,.gitpr.issue.md,.gitpr.blame.md) and the Linter (.gitpr.linter.yml) at the project root.-isor--issue: Automatically generates a draft of a standardized Issue and opens an interactive interface (TUI) for editing or direct submission via REST API. This feature has 3 context engines depending on the command combination:- New Code Issue (
gitpr -is): Reads the currentgit diff. Why use: Ideal for quickly documenting the task you just finished programming, before committing. - Epic/Release Issue (
gitpr -is -ht): Reads the full history of the current branch (Git Log + PR Cache). Why use: Ideal for generating consolidated documentation of an entire release or a large feature that took several days/commits to complete. - Archaeological/Technical Debt Issue (
gitpr -is -b file:lines): Reads the timeline of a specific business rule. Why use: Ideal for documenting technical debt, explaining how a legacy code block evolved and why it needs to be refactored.
- New Code Issue (
-hor--help: Shows the general help with all options. Use together with another flag for contextual help (e.g.:gitpr -h --issue,gitpr -h --linter) with a direct link to the detailed documentation of each feature.-uor--update: Checks and installs the latest version of GitPR (Auto-Updater).
⚙️ Technical Note (--hook): GitPR has a hidden flag
--hook <file>that is triggered exclusively by the Git Hooks system in the background. It allows the AI to inject the suggested message directly into Git's temporary file, without cluttering your terminal.
🛡️ Local Linter (Static Analysis)
GitPR CLI allows you to define strict rules that will be validated instantly during --review or --fullreview, without depending on AI. This is ideal for preventing common errors (like console.log or test IPs) from reaching the repository.
How to configure .gitpr.linter.yml:
When running gitpr --skill, a template will be generated. You can configure rules using Regular Expressions (Regex):
rules:
- name: "check-localhost"
extensions: ["js", "php"] # Extensions to be validated
regex: 'http(s)?://(localhost|127\.0\.0\.1)' # What to look for
message: "🚨 Localhost usage detected in file {file_name}"
ignore_comments: true # Ignores if the line is commented
ignore_paths: # Folders or files ignored (accepts *)
- "vendor/*"
- "node_modules/*"
The Linter analyzes only the added lines in your git diff, ensuring a focused and extremely fast execution. If there are violations, they will appear highlighted at the top of your review file.
🧠 Multi-Model Architecture (AI-Agnostic)
GitPR is not tied to a single Artificial Intelligence. During initial setup, the user can choose their default engine. We currently support:
- Google Gemini (Default:
gemini-2.5-flash) - DeepSeek (Default:
deepseek-chat)
You can dynamically switch models by configuring the GEMINI_API_MODEL or DEEPSEEK_API_MODEL variables in your ~/.gitpr/.env file, or switch in real-time using the --provider flag.
🎯 Customizable "Skills" System (Prompt Engineering)
Instead of hiding AI instructions in the source code, GitPR uses local Markdown files that act as System Instructions. When running gitpr -s, the following files are generated at the root of your project to customize the AI's "persona" according to your company's business rules:
.gitpr.commit.md: Rules for generating short commit messages..gitpr.pr.md: Required topic structure for the Pull Request description..gitpr.review.md: Defines the architectural focus (e.g.: SOLID, Clean Code) for diff analysis..gitpr.filereview.md: Defines strict cohesion and coupling rules for full file auditing (used with--input)..gitpr.issue.md: Defines the structure and level of detail required for generating standardized Issues (used with--issue)..gitpr.blame.md: Defines the focus of archaeological analysis for legacy code tracing (used with--blame).
🌐 Internationalization (i18n)
GitPR automatically detects your system language and displays messages in your native language. The i18n system is inspired by Laravel's __() helper:
- Auto-detection: On first run, GitPR detects your OS language and saves it to
~/.gitpr/.env(GITPR_LANG). - Translation files: Language packs are downloaded automatically from the official repository to
~/.gitpr/langs/. - English fallback: If a translation is missing, the English text is displayed directly.
- Developer API: Use
from src.i18n import __and wrap all user-facing strings with__("Your text here"). - Placeholders: Supports named parameters —
__("Downloading {file}...", file="template.md").
To force a specific language, set GITPR_LANG=pt_br or GITPR_LANG=en in ~/.gitpr/.env.
📖 Full developer guide: docs/i18n_explanation.md — architecture, usage patterns, circular import precautions, and how to add new languages.
📚 Technical Documentation and Advanced Guides
To keep this README concise, we detail the most advanced DevOps and Continuous Integration focused implementations in separate documents.
If you want to implement GitPR as an automated quality barrier in your team, check out the guides below:
- Local Git Hooks (Shift-Left): How to use
gitpr --installhooksto create guardrails on the developer's machine and use AI to automatically write commit messages. - Customizable Static Linter: How to create validation rules in
.gitpr.linter.ymlfor CI/CD and pre-commit hooks. - Issue Generation and TUI Interface: How to use the terminal graphical interface (TUI) and the 3 context engines to manage structured Issues.
- AI Code Review: Guide to review modes (
--review,--fullreview) and file auditing (--input). - AI Commit Messages: How to generate messages in the Conventional Commits standard and integrate with Git Hooks.
- Code Archaeologist (Git Blame): How to trace the origin of business rules with
git blameand AI. - Skills and Templates System: How to customize AI behavior with
.gitpr.*.mdfiles. - Auto-Updater: How GitPR's automatic update (hot-swap) works.
- AI Providers: Configuration and selection between Google Gemini and DeepSeek.
- Pull Request (Default Mode): Complete flow for generating PR descriptions without flags.
- CI/CD Integration (GitHub Actions): How to run GitPR in the pipeline to block "Merge" of PRs with violations.
- GitHub Token (PAT) Integration and Security: Understand how GitPR creates issues directly in the repository with authentication.
⚡ Local Cache System (Quota Savings)
GitPR has an intelligent MD5-based cache engine. Whenever you run a command (--review, --commit, etc.), the tool generates an exact hash of your current code (diff) and instructions.
If you run the same command again without changing the code, GitPR intercepts the request and returns the result instantly (in milliseconds) from the ~/.gitpr/cache/prompts/ folder, saving you time and your Gemini API quotas!
🔄 Auto-Updater (Over-The-Air Update)
Never worry about manually downloading new versions again. GitPR has a Connection Guardian and a built-in updater:
- It checks network availability before starting so it doesn't block your offline workflow.
- On each execution, it silently checks if there is a new official release on the GitHub API.
- You can force the check and installation by running
gitpr --updateorgitpr -u. - The tool uses the Hot-Swap technique, downloading the new
.exeand transparently replacing the old version.
Publishing to PyPI
pipenv run python -m build
pipenv run twine upload dist/*
🤝 How to Contribute
Contributions are very welcome! To contribute:
- Fork the project.
- Create a branch for your feature (git checkout -b feature/NewFeature).
- Commit your changes (git commit -m 'feat: add new feature'). Tip: Use GitPR itself to generate this message! 😄
- Push to the branch (git push origin feature/NewFeature).
- Open a Pull Request.
✨ Acknowledgments and Authorship
Project conceived and developed by:
Natan Fiuza - contato@natanfiuza.dev.br
📄 License
This project is licensed under the GNU Lesser General Public License v2.1 (LGPL-2.1). See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gitpr_cli-0.0.24.tar.gz.
File metadata
- Download URL: gitpr_cli-0.0.24.tar.gz
- Upload date:
- Size: 48.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87ade264bded1f14e58dc4e2105da555f45b14d24d8c16029f8fa731254d68b1
|
|
| MD5 |
6a53cd43a513aa4e35d4b6376cf60bd4
|
|
| BLAKE2b-256 |
db747a53d81a581f899cc9a46004976edb72653356c16f5f1425e91943bea81d
|
File details
Details for the file gitpr_cli-0.0.24-py3-none-any.whl.
File metadata
- Download URL: gitpr_cli-0.0.24-py3-none-any.whl
- Upload date:
- Size: 53.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43c68a17e638d7d4b5aa749ec86bdb3c7ce48afa117b4c990a3e03e44f3ddca3
|
|
| MD5 |
795085889f973e486945fc901cf85a47
|
|
| BLAKE2b-256 |
59f58faf01ed907af88249f0642e223642fa6263529c3f98b82d808a07f99a56
|