Jelajahi Sumber

Add README explaining AI commit message generator

This commit adds a README file that explains the
AI-powered Git commit message generator tool. The tool
uses the Google Gemini API to analyze staged changes
and generate commit messages following standard Git
conventions. The README includes sections on features,
prerequisites, setup, usage, how it works, and the
files included in the repository. This provides
users with a comprehensive guide to using the tool and
understanding its functionality, which was previously
unavailable.
seno 6 hari lalu
induk
melakukan
6cec40ccbc
1 mengubah file dengan 68 tambahan dan 1 penghapusan
  1. 68 1
      README.md

+ 68 - 1
README.md

@@ -1 +1,68 @@
-# CREATE GEN-AI COMMIT MESSAGE
+# 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:**
+
+    ```bash
+    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:
+    ```bash
+    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:
+    ```bash
+    ./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.