conventional-commits icon indicating copy to clipboard operation
conventional-commits copied to clipboard

Support excluding merge commits

Open SamMousa opened this issue 2 years ago • 1 comments

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.

SamMousa avatar Feb 02 '22 08:02 SamMousa

@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"
                    }
                ]
            }
        ]
    }
}

gschafra avatar Dec 05 '22 10:12 gschafra