diff --git a/src/BaseCommand.php b/src/BaseCommand.php index 84ce5a5..9e210fb 100644 --- a/src/BaseCommand.php +++ b/src/BaseCommand.php @@ -2,6 +2,7 @@ namespace DrupalMaintenanceReporter; +use DrupalMaintenanceReporter\Exception\CommitsNotFoundException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -155,7 +156,7 @@ protected function getFirstCommit(string $date, string $branch, string $format = $first_commit = trim($this->runCommand("git log origin/$branch --after=$date --pretty=format:'$format' | tail -n1")->getOutput()); if (empty($first_commit)) { - throw new \Exception('There are no commits in the selected date!'); + throw new CommitsNotFoundException('There are no commits in the selected date!'); } return $first_commit; diff --git a/src/ComposerDiffPeriodCommand.php b/src/ComposerDiffPeriodCommand.php index 64db9bd..824bf10 100644 --- a/src/ComposerDiffPeriodCommand.php +++ b/src/ComposerDiffPeriodCommand.php @@ -2,6 +2,7 @@ namespace DrupalMaintenanceReporter; +use DrupalMaintenanceReporter\Exception\CommitsNotFoundException; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -25,7 +26,6 @@ protected function configure() { * {@inheritdoc} */ protected function initialize(InputInterface $input, OutputInterface $output) { - $this->showSummary($input, $output); $this->generateDirSkeleton(); } @@ -33,6 +33,13 @@ protected function initialize(InputInterface $input, OutputInterface $output) { * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) : int { + try { + $this->showSummary($input, $output); + } + catch (CommitsNotFoundException $exception) { + return $exception->handle($output); + } + $branch = $input->getArgument('branch'); $from = $input->getOption('from'); $to = $input->getOption('to'); diff --git a/src/Exception/CommitsNotFoundException.php b/src/Exception/CommitsNotFoundException.php index 76cf1dd..601716d 100644 --- a/src/Exception/CommitsNotFoundException.php +++ b/src/Exception/CommitsNotFoundException.php @@ -2,7 +2,25 @@ namespace DrupalMaintenanceReporter\Exception; +use Symfony\Component\Console\Output\OutputInterface; + /** * Thrown when there aren't commits found. */ -class CommitsNotFoundException extends \RuntimeException { } +class CommitsNotFoundException extends \RuntimeException { + + /** + * Helper to handle exceptions on not found commits. + * + * @param OutputInterface $output + * Output. + * + * @return int + * Exit code. + */ + public function handle(OutputInterface $output) { + $output->writeln('No code changes have been found.'); + return 0; + } + +} diff --git a/src/SecuritiesFixedCommand.php b/src/SecuritiesFixedCommand.php index 5283fc6..3bab3a1 100644 --- a/src/SecuritiesFixedCommand.php +++ b/src/SecuritiesFixedCommand.php @@ -2,6 +2,7 @@ namespace DrupalMaintenanceReporter; +use DrupalMaintenanceReporter\Exception\CommitsNotFoundException; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -19,7 +20,6 @@ class SecuritiesFixedCommand extends BaseCommand { * {@inheritdoc} */ protected function initialize(InputInterface $input, OutputInterface $output) { - $this->showSummary($input, $output); $this->generateDirSkeleton(); } @@ -35,6 +35,13 @@ protected function configure() { * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) : int { + try { + $this->showSummary($input, $output); + } + catch (CommitsNotFoundException $exception) { + return $exception->handle($output); + } + $branch = $input->getArgument('branch'); $from = $input->getOption('from'); $to = $input->getOption('to');