From a48ade83f640de86ef46aba7a23c15e9dd465b8a Mon Sep 17 00:00:00 2001 From: Ali Yaman Date: Mon, 18 Nov 2024 12:31:37 +0100 Subject: [PATCH] feat: update auto-merge commit message formatting and bump version to 2.7.0 --- conventional_commits_check/main.py | 8 +- index.rst | 188 ++++++++++++++++------------- setup.py | 2 +- 3 files changed, 112 insertions(+), 86 deletions(-) diff --git a/conventional_commits_check/main.py b/conventional_commits_check/main.py index e6bf24f..0ffd590 100644 --- a/conventional_commits_check/main.py +++ b/conventional_commits_check/main.py @@ -66,13 +66,13 @@ def handle_auto_merge_commit(commit_message, args): Returns: tuple: A tuple containing the updated commit message and a result message, or None if not an auto-merge. """ - merge_match = re.match(r"^Merge branch '(.+)' into '(.+)'", commit_message.strip()) + merge_match = re.match(r"^Merge", commit_message.strip()) if merge_match: - branch_from, branch_to = merge_match.groups() - formatted_message = f"merge: branch '{branch_from}' into '{branch_to}'" + # Remove the initial "Merge" and format the message + formatted_message = f"merge: {commit_message[6:].strip()}" if not args.emoji_disabled: formatted_message = f"πŸŽ‰ {formatted_message}" - return formatted_message, "πŸŽ‰ Auto-merge commit message formatted." + return formatted_message, "βœ… Auto-merge commit message successfully formatted." return None, None diff --git a/index.rst b/index.rst index 90d1982..8496c1b 100644 --- a/index.rst +++ b/index.rst @@ -1,106 +1,132 @@ -# Conventional Commits Check - - - -`conventional-commits-check` is a Python pre-commit hook that enforces Conventional Commits rules on your commit messages and automatically adds relevant emojis based on the commit type. - -Conventional Commits is a lightweight convention that provides a set of rules for creating an explicit commit history. This pre-commit hook helps ensure your commit messages adhere to the convention and provides additional context with emojis. - -# Automatic Emoji Insertion - -Automatic emoji insertion at the beginning of the Commit πŸŽ‰ - -```json -{ - "feat": "✨", - "fix": "πŸ›", - "docs": "πŸ“š", - "style": "πŸ’Ž", - "refactor": "🧹", - "perf": "πŸš€", - "test": "πŸ§ͺ", - "build": "πŸ—οΈ", - "ci": "πŸ‘·", - "chore": "♻️", - "revert": "βͺ", +# πŸŽ‰ Conventional Commits Check + +![PyPI Version](https://img.shields.io/pypi/v/conventional-commits-check) +![License](https://img.shields.io/github/license/AliYmn/conventional-commits-check) +![Last Commit](https://img.shields.io/github/last-commit/AliYmn/conventional-commits-check) +![Issues](https://img.shields.io/github/issues/AliYmn/conventional-commits-check) +![Stars](https://img.shields.io/github/stars/AliYmn/conventional-commits-check?style=social) +![Forks](https://img.shields.io/github/forks/AliYmn/conventional-commits-check?style=social) +![Downloads](https://img.shields.io/pypi/dm/conventional-commits-check) +![Contributors](https://img.shields.io/github/contributors/AliYmn/conventional-commits-check) + +![Result Image](https://raw.githubusercontent.com/AliYmn/conventional-commits-check/master/images/demo.png) + +`conventional-commits-check` is a powerful and easy-to-use Python pre-commit hook that helps enforce [Conventional Commits](https://www.conventionalcommits.org/) rules on your commit messages. It supports adding relevant emojis based on your commit types to enhance readability and bring some fun to your commit history! πŸš€ + +## πŸ“œ What are Conventional Commits? + +Conventional Commits provide a lightweight convention for creating a clear and explicit commit history. By using this hook, you'll ensure that your commit messages follow this convention, making your versioning easier to manage and your collaboration more seamless. + +## πŸ’‘ Features + +- βœ… Enforces Conventional Commits rules on your commit messages. +- 🎨 Optionally adds context-specific emojis to the start of commit messages. +- πŸ›‘ Blocks commits that do not conform to the Conventional Commits standard. +- πŸ”§ Allows for **custom commit types** and **custom emojis** via configuration. +- πŸ”„ **Auto-Merge Commit Handling**: Automatically formats auto-merge commit messages to follow a consistent style. + +## πŸ”„ Auto-Merge Commit Handling + +The `conventional-commits-check` tool includes functionality to handle auto-merge commit messages. When a commit message matches the pattern "Merge branch '...' into '...'", it is automatically reformatted to a more consistent style, such as "merge: branch '...' into '...'". If emojis are enabled, a πŸŽ‰ emoji is prepended to the message. This feature ensures that even auto-generated commit messages maintain a clean and readable format. + +## πŸ”§ Customization + +You can customize the commit types and their associated emojis by modifying the `commit_types.py` and `commits_check_config.yaml` files. These files allow you to define additional commit types and specify emojis for each type. + +### Example : [`commit_types.py`](https://github.com/AliYmn/conventional-commits-check/blob/master/conventional_commits_check/commit_types.py) + +```python +commit_types = { + "access": { + "description": "Improve accessibility.", + "emoji": "♿️" + }, + "analytics": { + "description": "Add or update analytics or track code.", + "emoji": "πŸ“ˆ" + }, + "animation": { + "description": "Add or update animations and transitions.", + "emoji": "πŸ’«" + }, + "arch": { + "description": "Make architectural changes.", + "emoji": "πŸ—οΈ" + }, + "assets": { + "description": "Add or update assets.", + "emoji": "🍱" + }, + "beer": { + "description": "Write code drunkenly.", + "emoji": "🍻" + }, + # ... more commit types ... } ``` -# Customization - -```bash -touch commits_check_config.yaml -```` +### Customizing Existing Emojis -`NOTE` : Please do not leave it blank if you create it. - -To add custom commit types and emojis, update your `commits_check_config.yaml` file with the additional_commands and additional_emojis fields. Here's an example: +You can also modify the emojis for existing commit types by updating the `commits_check_config.yaml`: ```yaml -additional_commands: - database: "^database(\\(.+\\))?:" - design: "^design(\\(.+\\))?:" - -additional_emojis: - database: "πŸ—ƒοΈ" - design: "🎨" -```` - -# Customization Current Emoji +additional_commit_types: + feat: + description: Introduce new features. + emoji: πŸŽ‰ + fix: + description: Fix a bug. + emoji: πŸ› οΈ +``` -This is how you can change the emojis of existing commands. +## βš™οΈ Installation -```yaml -additional_commands: - fix: "^fix(\\(.+\\))?:" - feat: "^feat(\\(.+\\))?:" +To add `conventional-commits-check` to your project, follow these steps: -additional_emojis: - fix: "πŸ—ƒοΈ" - feat: "🎨" -```` +1. **Update your `.pre-commit-config.yaml`:** -## Features + In your project’s root directory, add the following: -- Checks if commit messages follow the Conventional Commits rules. -- Adds an emoji to the commit message based on the commit type. -- Blocks commits with non-conforming messages. + ```yaml + repos: + - repo: https://github.com/AliYmn/conventional-commits-check + rev: v0.3.0 # Use the latest release version + hooks: + - id: conventional-commits-check + stages: [commit-msg] + args: ["--emoji-disabled"] # Use this argument to disable emojis + ``` -## Installation +2. **Install the pre-commit hook:** -Follow these steps to add the `conventional-commits-check` pre-commit hook to your project: + ```bash + pre-commit install --hook-type commit-msg -f + ``` -1. In your project's root directory, open the existing `.pre-commit-config.yaml` file (or create one if it doesn't exist) and add the following content: +3. **Install the `conventional-commits-check` package:** -```yaml -repos: - - repo: https://github.com/AliYmn/conventional-commits-check - rev: v0.3.0 # Use the latest release version - hooks: - - id: conventional-commits-check - stages: [commit-msg] -``` + ```bash + pip install -U conventional-commits-check + ``` -2. Update the pre-commit hooks in your project: +4. **Optional:** Update the pre-commit package: + ```bash + pre-commit autoupdate + ``` -```bash -pre-commit install --hook-type commit-msg -f -``` +## πŸš€ Usage -3. Install the conventional-commits-check package: +Once the hook is added, it will automatically run each time you make a commit. The hook checks your commit message against Conventional Commits rules, optionally adds the appropriate emoji, and prevents non-conforming commits. +## πŸ‘¨β€πŸ’» Contributing -```bash -pip install -U conventional-commits-check -``` +Contributions are welcome! Feel free to open issues or submit pull requests to enhance `conventional-commits-check`. Let’s make commits fun and consistent! πŸ˜„ -4. You may need to update the pre-commit package; +## πŸ“œ License -```bash -pre-commit autoupdate -``` +This project is licensed under the [MIT License](LICENSE). -# Usage +--- -Once the hook is added to your project, it will automatically run every time you create a commit. The hook will check the commit messages according to the Conventional Commits rules and add the corresponding emojis. If a commit message does not follow the rules, the commit will be blocked. \ No newline at end of file +Enhance your workflow and bring some life to your commits with `conventional-commits-check`! πŸŽ‰βœ¨πŸ› diff --git a/setup.py b/setup.py index f5bf674..d1bba68 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name="conventional-commits-check", - version="2.6.0", + version="2.7.0", description=("A pre-commit hook to check Conventional Commits and add emojis."), author="Ali Yaman", packages=find_packages(),