/** * Executes the current command. * * This method is not abstract because you can use this class * as a concrete class. In this case, instead of defining the * execute() method, you set the code to execute by passing * a Closure to the setCode() method. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null|int null or 0 if everything went fine, or an error code * * @see setCode() */ protected function execute(InputInterface $input, OutputInterface $output) { $styleHelper = new SymfonyStyle($input, $output); $validatorFactory = new ValidatorFactoryImplementation(); $validators = $validatorFactory->getMessageValidator(); $commitMessage = file_get_contents($input->getArgument(self::ARGUMENT_COMMIT_MESSAGE_FILE)); $commentCharacter = $input->getOption(self::OPTION_COMMENT_CHAR); $ignorePatterns = $input->getOption(self::OPTION_IGNORE); foreach ($ignorePatterns as $ignorePattern) { if (preg_match($ignorePattern, $commitMessage)) { return 0; } } $safeCommitMessage = preg_replace('/' . preg_quote($commentCharacter) . '.*/', '', $commitMessage); $message = new MessageImplementation($safeCommitMessage); $validators->validate($message); if (count($message->getStatuses()) < 1) { return 0; } $statusList = []; $isPositive = true; /** @var Status $status */ foreach ($message->getStatuses() as $status) { $statusList[] = $status->getMessage() . ' (' . $status->getDetailsUrl() . ')'; $isPositive = $status->isPositive() && $isPositive; } if ($isPositive) { return 0; } $styleHelper->error('Incorrectly formatted commit message'); $styleHelper->listing($statusList); $styleHelper->section('Your Commit Message'); $styleHelper->block($commitMessage); $styleHelper->warning('A commit has not been created'); return 1; }
/** * GitHubLintImplementation constructor. * * @param Client $client */ public function __construct(Client $client) { $validatorFactory = new ValidatorFactoryImplementation(); $this->analyser = new AnalysePullRequestCommitsImplementation(new CommitMessageServiceImplementation($client), new ValidateMessagesImplementation($validatorFactory->getMessageValidator()), new StatusSendServiceImplementation($client)); }