ai-commit-review
v1.0.4
Published
AI-powered commit and code analysis from the local Git repository
Maintainers
Readme
AI Commit Report
A command-line tool powered by AI for creating or analyzing Git commits and code directly from your local Git repository.
Table of Contents
- Introduction
- Installation
- Getting Started
- Usage
- Examples
- Dependencies
- Contributing
- License
- Notes and Suggestions
- Additional Tips
- Frequently Asked Questions (FAQs)
Introduction
AI Commit Report is a robust tool that utilizes the OpenAI API to assist with creating commits and analyzing code changes in Git repositories. It delivers detailed insights into modifications, evaluates adherence to best practices, and offers suggestions for improving code quality. By enhancing development efficiency, this tool also supports AI-driven commit creation, simplifying and optimizing your Git workflow.
Installation
Global Installation
To install the tool globally on your system, use the following command:
npm install -g ai-commit-review
This method simplifies the installation, eliminating the need to clone the repository and manually install dependencies.
Update
To update the tool to the latest version, use the command:
npm update -g ai-commit-review
This ensures that you are using the latest features and bug fixes available.
Uninstallation
To uninstall the tool globally, use the command:
npm uninstall -g ai-commit-review
Getting Started
Before using the tool, you must set your OpenAI API key, the desired model, and the response language.
Set the API Key
Use the set_config
command:
acr set_config OPENAI_API_KEY=sk-your-key
Set the OpenAI Model
Use the set_config
command:
acr set_config OPENAI_API_MODEL=gpt-4
Available Models:
The tool currently integrates only with OpenAI’s ChatGPT models:
gpt-4o
gpt-4o-mini
gpt-4
gpt-4-turbo
gpt-3.5-turbo
o1-preview
o1-mini
Set the Response Language
Use the set_config
command:
acr set_config OPENAI_RESPONSE_LANGUAGE=en-US
Available Languages:
EN_US
: English (US)EN_GB
: English (UK)ES
: SpanishZH
: MandarinHI
: HindiAR
: ArabicFR
: FrenchRU
: RussianPT_BR
: Portuguese (Brazil)PT_PT
: Portuguese (Portugal)
Usage
Analyze Commits
To analyze commits, navigate to the repository directory and run:
acr analyze
The tool will list the last 5 commits and prompt you to select the commits to be analyzed. Follow the instructions displayed:
- Controls: Press
<space>
to select,<a>
to toggle all,<i>
to invert selection, and<enter>
to proceed.
Create a Commit
To create a new commit with AI assistance, use:
acr create
Workflow:
- Confirm or Switch Branch: Ensures you are on the correct branch before making changes.
- Pull: Pull the latest changes from the remote repository.
- Clear the Stage: Clears the staging area to start fresh.
- Check for Conflicts: Verifies there are no merge conflicts.
- Stage All Changes: Stages all modified files.
- Generate Commit Message:
- AI Assistance: Generates a commit message based on the staged changes.
- Manual Entry: Allows you to write your own commit message.
- Edit Commit Message: Opens your default editor to finalize the commit message.
- Push to Remote: Optionally pushes the commit to the remote repository.
Show Help
To display help and view all available commands:
acr help
Examples
Analyze Commits:
acr analyze
Follow the instructions to select commits for analysis.
Create a New Commit with AI Assistance:
acr create
Follow the interactive prompts to generate or write your commit message.
Set the OpenAI API Key:
acr set_config OPENAI_API_KEY=your-key
Set the OpenAI Model:
acr set_config OPENAI_API_MODEL=gpt-4o-mini
Set the Response Language:
acr set_config OPENAI_RESPONSE_LANGUAGE=en-US
Update AI Commit Report:
npm update -g ai-commit-review
Updates the tool to the latest available version on npm.
Dependencies
- Node.js (version 14 or higher)
- npm
Contributing
Contributions are welcome! Feel free to open issues and pull requests in the repository.
How to Contribute
Fork the Project.
Create a New Branch:
git checkout -b my-feature
Make Your Changes.
Commit Your Changes:
git commit -m 'My new feature'
Push to the Remote Branch:
git push origin my-feature
Open a Pull Request.
Navigate to your fork on GitHub and click the "Compare & pull request" button to submit your changes for review.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Notes and Suggestions
- Focused Analysis: The tool analyzes only the changes (diffs) made in the selected commits, making the process more efficient and targeted.
- API Limitations: Be mindful of OpenAI API token limits. Analyzing only diffs helps avoid exceeding these limits.
- Sensitive Configurations: Do not expose your API key in public or in files that will be committed.
- Future Improvements:
- Implement unit tests to ensure code quality.
- Add support for additional OpenAI models as they become available.
- Enhance error handling and user messages.
- Support: If you encounter issues or have questions, open an issue on GitHub.
Additional Tips
- Efficiency: Analyzing only the changes speeds up the process and reduces API resource consumption.
- Focus on Changes: The analysis is more precise when focused on recent changes, helping to identify potential issues introduced.
- Security: Ensure no sensitive information is included in diffs or logs.
- Updates: Keep your dependencies up-to-date to benefit from improvements and security fixes.
Frequently Asked Questions (FAQs)
Q: Can I use this tool with AI models other than OpenAI's ChatGPT?
A: Currently, the tool supports only OpenAI’s ChatGPT models. Support for additional models may be added in future updates.
Q: What should I do if I encounter an error during installation?
A: Ensure you have the required dependencies installed and the appropriate permissions. Check error messages for specific details and consider opening an issue on GitHub if the problem persists.
Q: How do I protect my API key when using this tool?
A: Never share your API key publicly. Use environment variables and avoid committing keys to the repository. Consider using secret management tools for added security.
Q: What languages are available for analysis responses?
A: Responses can be configured in the following languages:
- English (US) -
en-US
- English (UK) -
en-GB
- Spanish -
es
- Mandarin -
zh
- Hindi -
hi
- Arabic -
ar
- French -
fr
- Russian -
ru
- Portuguese (Brazil) -
pt-BR
- Portuguese (Portugal) -
pt-PT