Skip to content

Latest commit

 

History

History
94 lines (73 loc) · 3.02 KB

File metadata and controls

94 lines (73 loc) · 3.02 KB

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:

  1. Summary: A brief overview (no more than 50 characters).
  2. 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.
  • Check if the diff is an atomic PR and offer a reason.
  • 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

  1. Install it globally.

    npm install -g commit-summarize
  2. 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.

  1. Clone the repository:
    git clone https://github.com/chienweiluo/commit-summarize.git
    cd commit-summarize
  2. Install the required packages.
  3. Copy the index.cjs to your project and run it.
    node index.cjs
  4. 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:
    export USE_LOCAL_MODEL=true && node index.cjs

After running the script, it will ask you to confirm the diff.

  1. Check the diff and answer the yes/no question to confirm the diff.

  2. 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

Open AI API Doc

Reddit: readline

Nodejs: readline interface

DeepSeek API

Ollama github

📄 License

This project is licensed under the MIT License.

This document is generated by AI.