Example #1
0
 /**
  * @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));
         }
     }
 }
Example #2
0
 /**
  * @param array  $config
  * @param string $commitMessage
  * @param string $rule
  *
  * @throws RuntimeException
  */
 private function runMatcher(array $config, $commitMessage, $rule)
 {
     $regex = new Regex($rule);
     if ((bool) $config['case_insensitive']) {
         $regex->addPatternModifier('i');
     }
     if ((bool) $config['multiline']) {
         $regex->addPatternModifier('m');
     }
     $additionalModifiersArray = array_filter(str_split((string) $config['additional_modifiers']));
     array_map([$regex, 'addPatternModifier'], $additionalModifiersArray);
     if (!preg_match((string) $regex, $commitMessage)) {
         throw new RuntimeException(sprintf('The commit message does not match the rule: %s', $rule));
     }
 }