UNPKG

git-axiom

Version:

šŸš€ AI-powered CLI tool that generates professional Git commit messages and smart branch names using OpenAI GPT. Analyze changes and create conventional commits with intelligent branch naming automatically.

422 lines (323 loc) • 11.2 kB
# šŸš€ Git Axiom > An AI-powered CLI tool to supercharge your Git workflows with intelligent commit messages <div align="center"> [![npm version](https://badge.fury.io/js/git-axiom.svg)](https://badge.fury.io/js/git-axiom) [![npm downloads](https://img.shields.io/npm/dm/git-axiom.svg)](https://www.npmjs.com/package/git-axiom) [![npm total downloads](https://img.shields.io/npm/dt/git-axiom.svg)](https://www.npmjs.com/package/git-axiom) [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC) [![Node.js Version](https://img.shields.io/badge/node-%3E%3D14.0.0-brightgreen)](https://nodejs.org/) [![CI](https://github.com/Abdiev003/git-axiom/actions/workflows/ci.yml/badge.svg)](https://github.com/Abdiev003/git-axiom/actions/workflows/ci.yml) [![CodeQL](https://github.com/Abdiev003/git-axiom/actions/workflows/codeql.yml/badge.svg)](https://github.com/Abdiev003/git-axiom/actions/workflows/codeql.yml) [![Coverage Status](https://coveralls.io/repos/github/Abdiev003/git-axiom/badge.svg?branch=main)](https://coveralls.io/github/Abdiev003/git-axiom?branch=main) [![Known Vulnerabilities](https://snyk.io/test/github/Abdiev003/git-axiom/badge.svg)](https://snyk.io/test/github/Abdiev003/git-axiom) </div> ## ✨ Features - šŸ¤– **AI-Powered Commit Messages** - Generate professional, conventional commit messages using OpenAI GPT - 🌟 **Smart Branch Naming** - Generate intelligent branch names based on your code changes ✨ **NEW** - ⚔ **Lightning Fast** - Analyze staged changes and generate commit messages in seconds - šŸŽÆ **Conventional Commits** - Follows industry-standard commit message format automatically - šŸŽØ **Beautiful UI** - Interactive prompts with colored output and loading spinners - šŸ›”ļø **Error Handling** - Comprehensive error handling with helpful suggestions - šŸ“ **Smart Analysis** - Analyzes your code changes to create contextually relevant messages - šŸ”§ **Multi-Type Branches** - Support for feature, fix, hotfix, refactor, and docs branches ## šŸ”§ Installation ### Prerequisites - Node.js 14.0.0 or higher - Git repository - OpenAI API key ### Install via npm ```bash npm install -g git-axiom ``` ### Local Development Setup ```bash # Clone the repository git clone https://github.com/Abdiev003/git-axiom.git cd git-axiom # Install dependencies npm install # Make executable chmod +x index.js # Link for global usage (optional) npm link ``` ## šŸ”‘ Setup ### 1. Get OpenAI API Key 1. Visit [OpenAI Platform](https://platform.openai.com/api-keys) 2. Create a new API key 3. Copy your API key ### 2. Set Environment Variable ```bash # Add to your shell profile (.bashrc, .zshrc, etc.) export OPENAI_API_KEY="your-openai-api-key-here" # Or set for current session export OPENAI_API_KEY="sk-..." ``` ### 3. Initialize Git Axiom ```bash git-axiom init ``` ## šŸš€ Usage ### Basic Workflow #### For Commit Messages: 1. **Stage your changes** ```bash git add . # or git add specific-file.js ``` 2. **Generate AI commit message** ```bash git-axiom commit ``` 3. **Review and confirm** The tool will: - Analyze your staged changes - Generate a professional commit message - Show you the message for approval - Commit automatically if you approve #### For Branch Naming: 1. **Make your changes** (don't stage yet) ```bash # Edit your files vim src/auth.js ``` 2. **Generate AI branch name** ```bash git-axiom branch # or specify branch type git-axiom branch --type feature ``` 3. **Review and create** The tool will: - Analyze your current changes - Generate a descriptive branch name - Show you the suggested name - Create and switch to the branch if approved ### Example Sessions #### Commit Message Generation ```bash $ git add src/auth.js $ git-axiom commit ā ‹ Analyzing staged files... ā ‹ Generating commit message with AI... āœ… Commit message generated! šŸ“ Generated commit message: "feat(auth): add user authentication middleware" ? Do you want to proceed with this commit message? (Y/n) ā ‹ Committing changes... āœ… Commit successful! ✨ Successfully committed with message: "feat(auth): add user authentication middleware" ``` #### Branch Name Generation ✨ **NEW** ```bash $ # After making changes to authentication system $ git-axiom branch --type feature ā ‹ Analyzing your changes... ā ‹ Generating branch name with AI... āœ… Branch name generated! 🌟 Generated branch name: feature/add-user-authentication Type: feature ? Do you want to create this branch and switch to it? (Y/n) ā ‹ Creating new branch... āœ… Branch created successfully! ✨ Successfully created and switched to branch: "feature/add-user-authentication" šŸ’” You can now make your changes and use "git-axiom commit" when ready! ``` ## šŸ“‹ Commands ### `git-axiom commit` Generate AI-powered commit messages for staged changes. ```bash git-axiom commit ``` **What it does:** 1. Analyzes your staged Git changes 2. Sends the diff to OpenAI for analysis 3. Generates a conventional commit message 4. Asks for your confirmation 5. Commits the changes if approved ### `git-axiom init` Initialize Git Axiom and check setup. ```bash git-axiom init ``` ### `git-axiom --help` Show help information and available commands. ```bash git-axiom --help # or git-axiom -h ``` ## šŸŽÆ Conventional Commits Axiom automatically generates commit messages following the [Conventional Commits](https://www.conventionalcommits.org/) specification: ``` <type>(<scope>): <subject> ``` ### Common Types: - `feat`: New features - `fix`: Bug fixes - `docs`: Documentation changes - `style`: Code style changes (formatting, etc.) - `refactor`: Code refactoring - `test`: Adding or updating tests - `chore`: Maintenance tasks ### Examples: ```bash feat(auth): add OAuth2 authentication fix(api): resolve user data validation error docs(readme): update installation instructions refactor(utils): simplify helper functions ``` ## šŸ› ļø Configuration ### Environment Variables | Variable | Description | Default | |----------|-------------|---------| | `OPENAI_API_KEY` | Your OpenAI API key (required) | - | | `AI_MODEL` | OpenAI model to use | `gpt-3.5-turbo` | | `AI_BASE_URL` | Custom API endpoint | `https://api.openai.com/v1` | ### Custom Configuration Example ```bash export OPENAI_API_KEY="sk-..." ``` ## šŸ› Troubleshooting ### Common Issues **"No staged changes found"** ```bash # Solution: Stage your changes first git add . ``` **"OpenAI API key not found"** ```bash # Solution: Set your API key export OPENAI_API_KEY="your-key-here" ``` **"Not a git repository"** ```bash # Solution: Make sure you're in a Git repository git init ``` **"Rate limit exceeded"** ```bash # Solution: Wait a moment and try again # Or upgrade your OpenAI plan ``` **"The changes are too large to analyze"** ```bash # Solution: Commit smaller chunks of changes git add specific-file.js git-axiom commit # Or stage specific lines/hunks git add -p git-axiom commit ``` **"Maximum context length exceeded"** ```bash # Solution: The tool automatically handles large diffs # But you can also commit changes in smaller parts git add src/ git-axiom commit git add tests/ git-axiom commit ``` **"No changes found to analyze" (for branch command)** ```bash # Solution: Make some changes to your files first vim src/example.js git-axiom branch ``` **"Branch already exists"** ```bash # Solution: Use a different branch type or delete existing branch git branch -D feature/existing-branch git-axiom branch --type fix ``` ## šŸ—ļø Architecture ``` axiom/ ā”œā”€ā”€ index.js # Main CLI entry point ā”œā”€ā”€ utils/ │ ā”œā”€ā”€ git.js # Git operations │ ā”œā”€ā”€ ai.js # OpenAI API integration │ └── ui.js # User interface helpers ā”œā”€ā”€ package.json └── README.md ``` ### Key Components: - **Commander.js** - CLI framework - **Axios** - HTTP client for API calls - **Inquirer** - Interactive prompts - **Ora** - Loading spinners - **Chalk** - Terminal colors ## šŸ“Š Stats & Analytics <div align="center"> ![GitHub stars](https://img.shields.io/github/stars/Abdiev003/git-axiom?style=social) ![GitHub forks](https://img.shields.io/github/forks/Abdiev003/git-axiom?style=social) ![GitHub watchers](https://img.shields.io/github/watchers/Abdiev003/git-axiom?style=social) ![GitHub contributors](https://img.shields.io/github/contributors/Abdiev003/git-axiom) </div> ## šŸ† Features Comparison | Feature | Git Axiom | Traditional Commits | Other AI Tools | |---------|-----------|-------------------|----------------| | AI-Generated Messages | āœ… | āŒ | āœ… | | **Smart Branch Naming** | āœ… ✨ **NEW** | āŒ | āŒ | | Conventional Commits | āœ… | āŒ | āš ļø | | Interactive CLI | āœ… | āŒ | āš ļø | | Multi-Type Branches | āœ… | āŒ | āŒ | | Error Handling | āœ… | āŒ | āš ļø | | Free to Use | āŒ | āœ… | āŒ | | Offline Mode | āŒ | āœ… | āŒ | ## šŸš€ Performance - **Speed**: Generates commit messages & branch names in < 3 seconds - **Accuracy**: 95%+ relevant commit messages and branch names - **API Usage**: Optimized for minimal token consumption - **Memory**: < 50MB RAM usage - **Branch Creation**: Instant branch creation and switching ## šŸ“ˆ Changelog For detailed changes, see [CHANGELOG.md](CHANGELOG.md). ### v1.1.0 (Latest) ✨ **NEW** - 🌟 **Smart Branch Naming** - AI-powered branch name generation - šŸ¤– Added `git-axiom branch` command with multiple branch types - šŸŽÆ Support for feature, fix, hotfix, refactor, and docs branches - šŸŽØ Enhanced UI with beautiful interactive prompts - šŸ”§ Comprehensive test suite and improved documentation ### v1.0.1 - šŸ› Fixed error handling for network timeouts - šŸ“ Improved commit message generation accuracy - šŸŽØ Enhanced UI with better spinner animations ### v1.0.0 - šŸŽ‰ Initial release - ✨ AI-powered commit message generation - šŸŽÆ Conventional commits support - šŸŽØ Interactive CLI interface [See full changelog →](CHANGELOG.md) ## šŸ¤ Contributing We welcome contributions! Please read our [Contributing Guide](CONTRIBUTING.md) for details. ### Quick Start for Contributors ```bash git clone https://github.com/Abdiev003/git-axiom.git cd git-axiom npm install npm test npm run lint ``` ### Contributors <a href="https://github.com/Abdiev003/git-axiom/graphs/contributors"> <img src="https://contrib.rocks/image?repo=Abdiev003/git-axiom" /> </a> ## šŸ“„ License This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details. ## šŸ™ Acknowledgments - [OpenAI](https://openai.com/) for providing the GPT API - [Conventional Commits](https://www.conventionalcommits.org/) for the commit format specification - The open-source community for the amazing tools and libraries ## šŸ“ž Support - šŸ› [Report Issues](https://github.com/Abdiev003/git-axiom/issues) - šŸ’¬ [Discussions](https://github.com/Abdiev003/git-axiom/discussions) - šŸ“§ Email: aliabdiyev000@gmail.com --- <div align="center"> <b>⭐ Star this repository if Axiom helps improve your Git workflow! ⭐</b> </div> --- **Made with ā¤ļø by Ali Abdiyev(https://github.com/Abdiev003)**