ramsey / conventional-commits

:yo_yo: A PHP library for creating and validating commit messages according to the Conventional Commits specification. Includes a CaptainHook plugin!
MIT License
182 stars 21 forks source link

Support excluding merge commits #41

Open SamMousa opened 2 years ago

SamMousa commented 2 years ago

It would be great if we could easily (and maybe even by default) exclude merge commits from the requirement.

Quick merge

When doing a merge of 2 branches that use proper commit messages, the automated merge commit message doesn't really matter and shouldn't be subject to the strict structure of conventional commits.

Background/problem

I want to merge

Proposal/solution

Add an ignore pattern that matches the auto generated merge commit messages.

Alternatives

Write a merge: commit message for every merge.

gschafra commented 1 year ago

@SamMousa Alternative solution would be implementing a custom Condition which checks if a merge is in progress. I've implemented following and it seems to work:

src/HookConditions/NotMerge.php:

<?php

    namespace App\HookConditions;

    use CaptainHook\App\Console\IO;
    use CaptainHook\App\Hook\Condition;
    use SebastianFeldmann\Git\Repository;

    class NotMerge implements Condition
    {

        /**
         * @inheritDoc
         */
        public function isTrue(IO $io, Repository $repository): bool
        {
            return !$repository->isMerging();
        }
    }

captainhook.json:

{
    "commit-msg": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Ramsey\\CaptainHook\\ValidateConventionalCommit",
                "options": {
                    "config": {
                        "typeCase": null,
                        "types": [],
                        "scopeCase": null,
                        "scopeRequired": false,
                        "scopes": [],
                        "descriptionCase": null,
                        "descriptionEndMark": null,
                        "bodyRequired": false,
                        "bodyWrapWidth": null,
                        "requiredFooters": []
                    }
                },
                "conditions": [
                    {
                        "exec": "\\App\\HookConditions\\NotMerge"
                    }
                ]
            }
        ]
    }
}