1.0.2 • Published 5 months ago
commit-summarize v1.0.2
AI-Powered Commit Message Script
This Node.js script automatically generates concise and descriptive Git commit messages using OpenAI's API. It analyzes your staged changes and provides a meaningful commit message in two parts:
- Summary: A brief overview (no more than 50 characters).
- Description: Bullet points outlining the changes.
🚀 Features
- Extracts staged Git changes
- Functional programming style using Ramda for cleaner code
- Utilizes OpenAI GPT-4 for generating commit messages
- Support to use local model(deepseek-r1 on ollama) with USE_LOCAL_MODEL=true.
- Security
- Sanitize diffs and filenames.
- Restrict to safe file types
- Remove comments.
- Confirmation diff before send.
- Enable to use local model with ollama, avoid code exposure.
- Anonymize variable names On the way
📦 Installation & Usage
Install it globally.
npm install -g commit-summarize
Install the required packages:
export USE_LOCAL_MODEL=true && commit-summarize or export OPEN_API_KEY_COMMIT=YOUR_KEY && commit-summarize
Or clone the repository and run it locally.
Clone the repository:
git clone https://github.com/chienweiluo/commit-summarize.git cd commit-summarize
- Install the required packages.
- Copy the index.cjs to your project and run it.
node index.cjs
Run the script:
- If you want to use OpenAI API, you can set the following environment variable:
export OPEN_API_KEY_COMMIT=YOUR_KEY && node index.cjs
- If you want to use local model (deepseek-r1 on ollama), you can set the following environment variable:
After running the script, it will ask you to confirm the diff.export USE_LOCAL_MODEL=true && node index.cjs
- If you want to use OpenAI API, you can set the following environment variable:
Check the diff and answer the yes/no question to confirm the diff.
Wait for the script to generate the commit message. like this:
**Summary:** Update environment variable handling and logging
**Description:**
- Changed the environment variable from `XXX` to `YYY`.
- Updated console log message for empty changed files for improved clarity.
...
🛠️ Code Reference
The main idea of this script is inspired by an article from August. Many thanks to him for his outstanding articles.
Related Links
AI Git Commit by August@letswritetw
How To Get Your Own OpenAI API Key
📄 License
This project is licensed under the MIT License.
This document is generated by AI.