Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/danilop/commit-message-generator

Elevate your Git workflow with intelligent, context-aware commit messages generated by an AI language model.
https://github.com/danilop/commit-message-generator

Last synced: 2 months ago
JSON representation

Elevate your Git workflow with intelligent, context-aware commit messages generated by an AI language model.

Awesome Lists containing this project

README

        

# 🤖 AI-Powered Git Commit Message Generator

Elevate your Git workflow with intelligent, context-aware commit messages generated by an AI language model.

## 🌟 Features

- **AI-Powered**: Leverages AI models via Amazon Bedrock for high-quality commit message generation.
- **Context-Aware**: Analyzes file changes, diffs, and commit history for comprehensive understanding.
- **Smart Formatting**: Generates commit messages following best practices, including summary lines and detailed explanations.
- **Interactive**: Allows user review and approval of generated commit messages.
- **Git-Integrated**: Seamlessly works with your existing Git workflow.
- **Customizable**: Supports debug mode for detailed logging and troubleshooting.

## 🚀 Quick Start

1. **Clone the repository:**
```
git clone https://github.com/yourusername/commit-message-generator.git
cd commit-message-generator
```

2. **Install dependencies:**
```
pip install -r requirements.txt
```

3. **Set up AWS credentials:**
Ensure your AWS credentials are configured with access to Amazon Bedrock.

4. **Add the script to your PATH:**
```
export PATH="$PATH:/path/to/commit-message-generator"
```

5. **Run the script from within your repository:**
```
commit-message-generator.py
```

5. **Review and approve** the generated commit message.

## 🛠️ Usage

After staging your changes in Git, run the script (it should be in your `PATH`):

```
commit-message-generator.py [--debug]
```

The script will:
1. Analyze staged changes
2. Generate a commit message using an AI model
3. Display the message for your review
4. Commit the changes if you approve

Use the `--debug` flag for (very) detailed logging.

## 🧠 How It Works

1. **File Analysis**: Gathers information about staged files, including content, history, and diffs.
2. **Prompt Generation**: Creates a detailed XML-formatted prompt, including file changes and commit context.
3. **AI Processing**: Sends the prompt to Amazon Bedrock for intelligent analysis.
4. **Message Generation**: The model generates a contextually relevant and well-formatted commit message.
5. **User Interaction**: Presents the generated message for user review and approval.
6. **Git Integration**: Commits the changes using the approved message.

## 📝 Sample Output

```sh
% git status
On branch main
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: commit-message-generator.py

no changes added to commit (use "git add" and/or "git commit -a")
% git add .
% commit-message-generator.py
2024-10-23 16:50:40,625 - INFO - Found 1 staged files
2024-10-23 16:50:40,648 - INFO - Found 0 non-staged changes
2024-10-23 16:50:48,496 - INFO -
Suggested commit message:
--------------------------------------------------
Add prompt truncation and move XML order for better performance

- Introduce MAX_PROMPT_SIZE constant to limit prompt size
- Truncate prompt if it exceeds maximum size and log a warning
- Reorder XML tags to send diffs before content for efficiency

This commit optimizes the commit message generator by:

- Adding a maximum prompt size limit to avoid sending excessively large prompts to the model
- Truncating prompts that exceed the size limit and logging a warning
- Reordering the XML tags to send file diffs before content, allowing the model to process diffs first for better performance

These changes help improve the efficiency and reliability of the commit message generation process, especially for repositories with large files or many changes.
--------------------------------------------------

Would you like to use this commit message? (y/n): y
2024-10-23 16:50:56,662 - INFO - Successfully committed changes: [main 98971fb] Add prompt truncation and move XML order for better performance
1 file changed, 10 insertions(+), 2 deletions(-)

Changes committed successfully!
```

## 🔧 Configuration

The script uses the following configuration:

- **AWS Region**: Set to `us-east-1` by default. Modify the `AWS_REGION` variable in the script if needed.
- **Anthropic's Claude Model**: Uses Anthropic Claude 3.5 Sonnet (`anthropic.claude-3-sonnet-20240229-v1:0`). Update the `MODEL_ID` to use a different model/version.

## 🚨 Error Handling

The script includes robust error handling:

- Checks if the current directory is a Git repository
- Validates the presence of staged changes
- Handles file reading errors gracefully
- Manages API call failures

If you encounter issues, run the script with the `--debug` flag for more detailed logging.

## 🤝 Contributing

Contributions are welcome! Here's how you can contribute:

1. Fork the repository
2. Create a new branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Commit your changes (`git commit -m 'Add some amazing feature'`)
5. Push to the branch (`git push origin feature/amazing-feature`)
6. Open a Pull Request

Please ensure your code adheres to the existing style and includes appropriate tests.

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

Happy committing! 🎉 Let AI supercharge your Git workflow!