Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip additional checks if a merge commit #1100

Merged
merged 11 commits into from
Jul 20, 2023
14 changes: 12 additions & 2 deletions src/Task/Git/CommitMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

class CommitMessage implements TaskInterface
{
const MERGE_COMMIT_REGEX =
'(Merge branch|tag \'.+\'(?:\s.+)?|Merge remote-tracking branch \'.+\'|Merge pull request #\d+\s.+)';

/**
* @var TaskConfigInterface
*/
Expand Down Expand Up @@ -135,6 +138,9 @@ public function run(ContextInterface $context): TaskResultInterface
);
}

if ($this->isMergeCommit($commitMessage)) {
return TaskResult::createSkipped($this, $context);
}

if ($this->enforceTypeScopeConventions()) {
try {
Expand Down Expand Up @@ -362,8 +368,7 @@ private function checkTypeScopeConventions(GitCommitMsgContext $context): void
? $config['type_scope_conventions']['subject_pattern']
: '([a-zA-Z0-9-_ #@\'\/\\"]+)';

$mergePattern =
'(Merge branch|tag \'.+\'(?:\s.+)?|Merge remote-tracking branch \'.+\'|Merge pull request #\d+\s.+)';
$mergePattern = self::MERGE_COMMIT_REGEX;

if (count($types) > 0) {
$types = implode('|', $types);
Expand All @@ -383,6 +388,11 @@ private function checkTypeScopeConventions(GitCommitMsgContext $context): void
}
}

private function isMergeCommit($commitMessage): bool
{
return (bool) \preg_match(self::MERGE_COMMIT_REGEX, $commitMessage);
}

/**
* Gets a clean subject line from the commit message
*
Expand Down