/**
  * @param Process $process
  *
  * @return string
  */
 public function format(Process $process)
 {
     $output = $process->getOutput();
     if (!$output) {
         return $process->getErrorOutput();
     }
     if (!$this->IO->isDecorated()) {
         return $output;
     }
     return $this->formatOutput($output);
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files) || empty($config['keywords'])) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('git');
     $arguments->add('grep');
     $arguments->add('--cached');
     $arguments->add('-n');
     $arguments->add('--break');
     $arguments->add('--heading');
     $arguments->addOptionalArgument('--color', $this->IO->isDecorated());
     $arguments->addArgumentArrayWithSeparatedValue('-e', $config['keywords']);
     $arguments->addFiles($files);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if ($process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, sprintf('You have blacklisted keywords in your commit:%s%s', PHP_EOL, $this->formatter->format($process)));
     }
     return TaskResult::createPassed($this, $context);
 }