/** * @param ContextInterface|GitCommitMsgContext $context */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $commitMessage = $context->getCommitMessage(); $exceptions = []; foreach ($config['matchers'] as $rule) { try { $this->runMatcher($config, $commitMessage, $rule); } catch (RuntimeException $e) { $exceptions[] = $e->getMessage(); } } if (count($exceptions)) { return TaskResult::createFailed($this, $context, implode(PHP_EOL, $exceptions)); } return TaskResult::createPassed($this, $context); }
/** * @param ContextInterface|GitCommitMsgContext $context */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $commitMessage = $context->getCommitMessage(); foreach ($config['matchers'] as $rule) { $regex = new Regex($rule); if ((bool) $config['case_insensitive']) { $regex->addPatternModifier('i'); } if ((bool) $config['multiline']) { $regex->addPatternModifier('m'); } if (!preg_match($regex->__toString(), $commitMessage)) { throw new RuntimeException(sprintf('The commit message does not match the rule: %s', $rule)); } } }
/** * @param ContextInterface|GitCommitMsgContext $context */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $commitMessage = $context->getCommitMessage(); foreach ($config['matchers'] as $rule) { $expression = Expression::create($rule); $regex = $expression->getRegex(); if ((bool) $config['case_insensitive']) { $regex->addOption('i'); } if ((bool) $config['multiline']) { $regex->addOption('m'); } if (!preg_match($regex->render(), $commitMessage)) { throw new RuntimeException(sprintf('The commit message does not match the rule: %s', $rule)); } } }