Skip to content

Conversation

@BSkaiTech
Copy link

Description

This PR introduces a comprehensive Git Commit Message Generator script that automatically generates conventional commit messages based on intelligent analysis of git changes. This tool significantly reduces the time developers spend writing commit messages while ensuring consistency across the project by strictly adhering to the Conventional Commits specification.

Problem Statement:
Writing meaningful and consistent commit messages is a time-consuming task that many developers struggle with. Inconsistent commit message formats make it difficult to understand project history, generate changelogs, and automate versioning. This script solves this problem by automatically analyzing code changes and generating appropriate commit messages that follow industry-standard conventions.

Solution:
The script provides an intelligent, feature-rich solution that:

  • Analyzes git diffs to understand what code was actually changed
  • Detects commit types based on file patterns, keywords, and change patterns
  • Infers commit scope from file paths and directory structure
  • Detects breaking changes automatically
  • Supports both interactive and automated workflows
  • Provides beautiful, colorized terminal output for better developer experience
  • Works seamlessly across Windows, Linux, and macOS platforms

Key Features Implemented:

  1. Intelligent Change Analysis: Deep analysis of git diffs including added/removed lines, file status, and binary file detection
  2. 25+ Commit Types: Comprehensive support for feat, fix, docs, style, refactor, perf, test, build, ci, chore, security, deps, config, ui, api, db, i18n, a11y, and more
  3. Breaking Change Detection: Automatic detection of breaking changes through keyword analysis and pattern matching
  4. Smart Scope Inference: Intelligent scope detection from file paths, directory structure, and common project layouts
  5. Interactive Mode: Full-featured interactive mode allowing users to customize type, scope, description, and breaking change status
  6. Quick Mode: Non-interactive mode for CI/CD pipelines and automated workflows
  7. Emoji Support: Optional emoji support with 25+ commit type emojis for better visual identification
  8. Colorized Output: Beautiful terminal colors with proper Windows console support
  9. Rich CLI: Comprehensive command-line interface with multiple options (--quick, --emoji, --staged, --dry-run, --amend, etc.)
  10. Advanced Pattern Matching: Sophisticated file pattern detection covering 100+ common file types and project structures
  11. Keyword Analysis: Deep keyword analysis in diffs to detect features, fixes, refactors, performance improvements, security issues, and more
  12. Cross-Platform: Full support for Windows (with ANSI color support), Linux, and macOS

Impact:
This tool will help developers save significant time on commit message writing, improve project commit history quality, enable better changelog generation, and facilitate automated semantic versioning. It's particularly valuable for teams that want to maintain consistent commit message standards without manual enforcement.

Dependencies

No external dependencies required. This script is designed to be completely self-contained and uses only Python 3.6+ standard library modules:

  • subprocess: Executes git commands to retrieve repository status, diffs, and commit information. Used for all git operations including git status, git diff, git commit, etc.

  • re: Performs pattern matching and regex operations for file pattern detection and keyword analysis. Essential for identifying commit types based on file paths and diff content.

  • sys: Handles system operations, exit codes, and standard input/output streams. Used for program termination, error handling, and TTY detection for color output.

  • os: Provides operating system interface for path operations and environment detection. Used for cross-platform compatibility checks.

  • argparse: Parses command-line arguments and provides help text. Enables the rich CLI with options like --quick, --emoji, --staged, --dry-run, etc.

  • pathlib: Modern path manipulation for cross-platform file path handling. Used for normalizing file paths and extracting directory structures for scope inference.

  • typing: Type hints for better code documentation and IDE support. Used throughout the codebase for type annotations (List, Dict, Tuple, Optional, etc.).

  • dataclasses: Data classes for structured data representation. Used for FileChange and CommitSuggestion classes to organize commit analysis data.

  • enum: Enumerations for commit types with associated metadata (name, description, emoji). Provides the CommitType enum with 25+ commit types.

  • ctypes: Windows-specific console mode configuration for ANSI color support. Only used on Windows to enable colored terminal output, fails gracefully on other platforms.

Why No External Dependencies:
The script intentionally avoids external dependencies to ensure:

  • Easy installation and deployment (no pip install required)
  • No dependency conflicts with other projects
  • Faster execution (no import overhead)
  • Better compatibility across different Python environments
  • Reduced security surface (no third-party code)

All functionality is implemented using Python's robust standard library, which is available in all Python 3.6+ installations. This makes the script immediately usable without any setup steps beyond having Python and Git installed.

Future Improvements

The following enhancements are planned for future versions to make this tool even more powerful:

  1. Configuration File Support: Allow users to define custom commit type patterns, scope mappings, and keyword rules via a configuration file (YAML/JSON/TOML). This will enable teams to customize the tool to match their specific project conventions and coding standards.

  2. Git Hooks Integration: Provide pre-commit and commit-msg hook templates for automatic commit message generation on every commit. This will make the tool seamlessly integrate into developer workflows without manual invocation.

  3. Issue Tracking Integration:

    • Automatic linking to GitHub/GitLab issues from commit messages
    • Support for Jira, Linear, and other issue tracking systems
    • Automatic issue number detection and inclusion in commit messages
    • Integration with project management tools
  4. Machine Learning Enhancement:

    • Train models on project-specific commit history for better message suggestions
    • Learn from user corrections to improve suggestions over time
    • Context-aware suggestions based on project patterns
  5. Multiple Template Support:

    • Support for different commit message templates (Angular, ESLint, etc.)
    • Custom template definition and selection
    • Template inheritance and composition
  6. Batch Processing:

    • Generate commit messages for multiple commits at once
    • Interactive rebase support for rewriting commit history
    • Bulk commit message updates
  7. Code Review Integration:

    • Integration with code review tools (GitHub, GitLab, Bitbucket)
    • Automatic PR description generation from commit messages
    • Link commits to pull requests automatically
  8. Validation Rules:

    • Configurable commit message validation rules
    • Integration with commitlint and similar tools
    • Pre-commit validation with helpful error messages
  9. Statistics and Analytics:

    • Track commit message quality metrics
    • Generate reports on commit message consistency
    • Team-wide commit message quality dashboards
  10. Editor Integration:

    • VSCode extension for inline commit message generation
    • Vim/Neovim plugin for terminal-based workflows
    • IDE integration for popular editors (PyCharm, Sublime, etc.)
  11. Multi-language Support:

    • Support for generating commit messages in different languages
    • Localization of the tool itself
    • Language detection from code comments and documentation
  12. API Mode:

    • REST API for integration with other tools
    • Webhook support for CI/CD pipelines
    • Programmatic access for automation scripts
  13. Enhanced Diff Analysis:

    • Better understanding of code structure changes
    • Detection of architectural changes
    • Identification of code smells and technical debt
  14. Collaborative Features:

    • Team-wide commit message style enforcement
    • Shared configuration across team members
    • Commit message review and approval workflows

Mentions

This contribution is part of the Daily Python Scripts collection, aimed at providing useful automation tools for developers. The script implements the Conventional Commits specification, which is widely adopted in the open-source community.

Acknowledgments:

  • The Conventional Commits specification community for establishing the standard
  • The Python open-source community for the robust standard library
  • All contributors to the Daily Python Scripts project

Community:
If you have suggestions, feedback, or would like to contribute improvements to this script, please feel free to:

  • Open an issue to discuss new features or report bugs
  • Submit a pull request with enhancements
  • Share your use cases and success stories
  • Contribute to documentation improvements

This tool is designed to be community-driven, and all contributions are welcome!

Developer's checklist

  • My PR follows the style guidelines of this project
  • I have performed a self-check on my work
  • My changes in code generate no new warnings
  • My changes are not breaking another fix/feature of the project
  • I have added README.md with problem statement and usage guide
  • I have added requirements.txt (empty as script uses stdlib only)
  • Code is written in Python 3
  • All comments and documentation are in English
  • Code follows PEP 8 style guidelines
  • Type hints are used throughout the codebase
  • Error handling is implemented for all git operations
  • Cross-platform compatibility is ensured (Windows/Linux/macOS)
  • The script has been tested on multiple platforms
  • All git commands are properly handled with error checking
  • The code is well-documented with docstrings
  • Interactive and non-interactive modes both work correctly
  • All command-line options have been tested
  • Color output works correctly on all supported platforms
  • Breaking change detection has been verified
  • Scope inference logic has been tested with various project structures

@github-actions
Copy link
Contributor

Thank you for opening your first pull request in our repository, one of our maintainers will get in touch with you soon.

PLEASE DON'T FORGET TO ADD YOUR EMAIL USING THE AUTH LINK

We at Metafy have some special rewards and swags for the top contributors in general repos and every contributor in web3 repos
For being eligible for that, please authenticate yourself using this link:
https://metafy.social/signup

Rewards : T-shirts & NFT ( for blockchain contributions )

Best of luck on your Contributions
For further queries you can join our discord for support : https://discord.gg/W6PmEjjQsA

@github-actions
Copy link
Contributor

PR is not linked to any issue, please make the corresponding changes in the body.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@BSkaiTech