Skip to content

The Node script automatically generates concise and descriptive Git commit messages using OpenAI's API or Deepseek-r1 on ollama

Notifications You must be signed in to change notification settings

chienweiluo/commit-summarize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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.

About

The Node script automatically generates concise and descriptive Git commit messages using OpenAI's API or Deepseek-r1 on ollama

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published