All Toolsโ€บAI-Powered Commit Message Linter
๐Ÿ”ง AI-Powered Code Review ToolsJune 5, 2026โœ… Tests passing

AI-Powered Commit Message Linter

A Python script that analyzes Git commit messages using AI, ensuring that they follow best practices for clarity, conciseness, and relevance. It flags ambiguous messages and suggests improvements to make them more informative and helpful.

What It Does

  • Analyze individual commit messages or all commit messages in a repository.
  • Provide AI-powered suggestions for improving commit message quality.
  • Highlight issues in commit messages.

Installation

1. Clone the repository:

git clone <repository-url>
   cd commit_message_linter

2. Install dependencies:

pip install gitpython openai colorama

Usage

Run the script with the following command:

python commit_message_linter.py --repo <path_to_git_repo> --api-key <your_openai_api_key>

Optional arguments:

  • --commit <commit_hash>: Analyze a specific commit message.

Example:

python commit_message_linter.py --repo ./my-repo --api-key YOUR_API_KEY

Source Code

import argparse
import os
import sys
from git import Repo, GitCommandError
from openai import ChatCompletion
from colorama import Fore, Style

def analyze_commit_message(message, api_key):
    """Analyze a commit message using OpenAI's API."""
    try:
        import openai
        openai.api_key = api_key
        response = ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=[
                {
                    "role": "system",
                    "content": "You are an assistant that reviews Git commit messages for clarity, conciseness, and relevance."
                },
                {
                    "role": "user",
                    "content": f"Review this commit message: {message}"
                }
            ]
        )
        return response['choices'][0]['message']['content']
    except Exception as e:
        return f"Error analyzing commit message: {e}"

def get_commit_messages(repo_path, commit_hash=None):
    """Retrieve commit messages from a Git repository."""
    try:
        repo = Repo(repo_path)
        if commit_hash:
            commit = repo.commit(commit_hash)
            return [commit.message.strip()]
        else:
            return [commit.message.strip() for commit in repo.iter_commits()]
    except GitCommandError as e:
        sys.exit(f"Git error: {e}")
    except Exception as e:
        sys.exit(f"Error accessing repository: {e}")

def main():
    parser = argparse.ArgumentParser(
        description="AI-Powered Commit Message Linter"
    )
    parser.add_argument(
        "--repo",
        type=str,
        required=True,
        help="Path to the Git repository"
    )
    parser.add_argument(
        "--commit",
        type=str,
        help="Specific commit hash to analyze (optional)"
    )
    parser.add_argument(
        "--api-key",
        type=str,
        required=True,
        help="OpenAI API key"
    )

    args = parser.parse_args()

    if not os.path.exists(args.repo):
        sys.exit("Error: The specified repository path does not exist.")

    commit_messages = get_commit_messages(args.repo, args.commit)

    for i, message in enumerate(commit_messages):
        print(f"{Fore.CYAN}Commit {i + 1}:{Style.RESET_ALL} {message}\n")
        print(f"{Fore.YELLOW}Analysis:{Style.RESET_ALL}")
        analysis = analyze_commit_message(message, args.api_key)
        print(f"{Fore.GREEN}{analysis}{Style.RESET_ALL}\n")

if __name__ == "__main__":
    main()

Community

Downloads

ยทยทยท

Rate this tool

No ratings yet โ€” be the first!

Details

Tool Name
commit_message_linter
Category
AI-Powered Code Review Tools
Generated
June 5, 2026
Tests
Passing โœ…
Fix Loops
2

Quick Install

Clone just this tool:

git clone --depth 1 --filter=blob:none --sparse \
  https://github.com/ptulin/autoaiforge.git
cd autoaiforge
git sparse-checkout set generated_tools/2026-06-05/commit_message_linter
cd generated_tools/2026-06-05/commit_message_linter
pip install -r requirements.txt 2>/dev/null || true
python commit_message_linter.py
AI-Powered Commit Message Linter โ€” AI Tools by AutoAIForge