Không có mô tả

seno 1dc3137814 Chore: Improve error handling and model selection 6 ngày trước cách đây
Dockerfile 8b7cb7ced1 Create initial files for AI commit generation 6 ngày trước cách đây
README.md 6cec40ccbc Add README explaining AI commit message generator 6 ngày trước cách đây
ai-commit.sh 1dc3137814 Chore: Improve error handling and model selection 6 ngày trước cách đây
git_commit_ai.py 1dc3137814 Chore: Improve error handling and model selection 6 ngày trước cách đây

README.md

AI-Powered Git Commit Message Generator

This tool automatically generates Git commit messages based on your staged changes using the Google Gemini API. It analyzes the diff of your staged files and suggests a commit message following conventional commit standards.

Features

  • Analyzes staged Git diffs.
  • Generates commit messages (subject and body) using the Gemini API.
  • Follows standard Git commit message conventions (imperative mood, character limits, separation of subject/body).
  • Runs in a Docker container for a consistent environment.
  • Prompts for user confirmation before creating the commit.

Prerequisites

  • Git: Must be installed on your host machine.
  • Docker: Must be installed and running on your host machine.
  • Gemini API Key: You need an API key from Google Cloud.

Setup

  1. Build the Docker Image:

    docker build -t docker.senomas.com/commit:1.0 .
    

    (Note: The tag docker.senomas.com/commit:1.0 is used in the ai-commit.sh script. You can change it if needed, but make sure to update the script accordingly.)

  2. Set Environment Variable: Export your Gemini API key as an environment variable:

    export GEMINI_API_KEY='YOUR_API_KEY'
    

    (Replace YOUR_API_KEY with your actual key. You might want to add this line to your shell profile (e.g., .bashrc, .zshrc, config.fish) for persistence.)

Usage

  1. Stage your changes: Use git add to stage the files you want to include in the commit.
  2. Run the script: Execute the ai-commit.sh script from the root of your Git repository:

    ./ai-commit.sh
    
  3. Review and Confirm: The script will:

    • Fetch the staged diff.
    • Generate a commit message using the Gemini API.
    • Print the generated message.
    • Ask for your confirmation (y/n).
  4. Commit: If you confirm ('y'), the script will create the commit using the generated message. If you decline ('n'), the commit will be aborted.

How it Works

  1. The ai-commit.sh script runs the git_commit_ai.py script inside a Docker container (docker.senomas.com/commit:1.0).
  2. It mounts the current directory (pwd) as /repo inside the container, allowing the script to access your Git repository.
  3. It mounts your .gitconfig and .git-credentials (read-only) for Git operations within the container.
  4. It passes the GEMINI_API_KEY environment variable into the container.
  5. The git_commit_ai.py script:
    • Retrieves the staged diff using git diff --staged.
    • Sends the diff to the Gemini API with a prompt asking for a commit message.
    • Receives the generated message.
    • Prompts the user for confirmation.
    • If confirmed, runs git commit -m "..." with the generated message.

Files

  • git_commit_ai.py: The main Python script that interacts with Git and the Gemini API.
  • Dockerfile: Defines the Docker image environment.
  • ai-commit.sh: A helper script to easily run the tool in Docker.
  • README.md: This file.