Skip to content

Commit

Permalink
Do not throw exceptions on not found commits
Browse files Browse the repository at this point in the history
  • Loading branch information
omarlopesino committed Mar 2, 2023
1 parent d3756cb commit 59851eb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/ComposerDiffPeriodCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,14 +26,20 @@ protected function configure() {
* {@inheritdoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output) {
$this->showSummary($input, $output);
$this->generateDirSkeleton();
}

/**
* {@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');
Expand Down
20 changes: 19 additions & 1 deletion src/Exception/CommitsNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
9 changes: 8 additions & 1 deletion src/SecuritiesFixedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +20,6 @@ class SecuritiesFixedCommand extends BaseCommand {
* {@inheritdoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output) {
$this->showSummary($input, $output);
$this->generateDirSkeleton();
}

Expand All @@ -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');
Expand Down

0 comments on commit 59851eb

Please sign in to comment.