diff --git a/dev/src/Command/RepoComplianceCommand.php b/dev/src/Command/RepoComplianceCommand.php index c75e3977207..fe7259bfe1c 100644 --- a/dev/src/Command/RepoComplianceCommand.php +++ b/dev/src/Command/RepoComplianceCommand.php @@ -46,8 +46,13 @@ protected function configure() { $this->setName('repo:compliance') ->setDescription('ensure all github repositories meet compliance') - ->addOption('component', 'c', InputOption::VALUE_REQUIRED, 'If specified, display repo info for this component only', '') - ->addOption('token', 't', InputOption::VALUE_REQUIRED, 'Github token to use for authentication', '') + ->addOption( + 'component', + 'c', + InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, + 'If specified, display repo info for this component only' + ) + ->addOption('token', 't', InputOption::VALUE_REQUIRED, 'Github token to use for authentication') ->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'can be "ci" or "table"', 'table') ->addOption('packagist-token', 'p', InputOption::VALUE_REQUIRED, 'Packagist token for the webhook') ; @@ -77,19 +82,20 @@ protected function execute(InputInterface $input, OutputInterface $output) ]; (clone $table)->setHeaders($headers)->render(); - $componentName = $input->getOption('component'); - $components = $componentName ? [new Component($componentName)] : Component::getComponents(); + $components = $input->getOption('component') + ? array_map(fn ($c) => new Component($c), $input->getOption('component')) + : Component::getComponents(); - $isCompliant = true; $emoji = fn ($check) => match ($check) { 'skipped' => '⚪', false => '❌', true => '✅', null => '❓'}; + $failed = []; foreach ($components as $i => $component) { $isNewComponent = $component->getPackageVersion() === '0.0.0' - || $component->getPackageVersion() === '0.1.0' && $format == 'ci'; + || ($component->getPackageVersion() === '0.1.0' && $format == 'ci'); do { $refreshDetails = false; if (!$details = $this->getRepoDetails($component)) { - $isCompliant = $settingsCheck = $packagistCheck = $webhookCheck = $teamCheck = false; + $settingsCheck = $packagistCheck = $webhookCheck = $teamCheck = false; $details = array_fill(0, count($headers) - 1, '**REPO NOT FOUND**'); $details[0] = str_replace('googleapis/', '', $component->getRepoName()); continue; @@ -122,14 +128,26 @@ protected function execute(InputInterface $input, OutputInterface $output) sprintf('%s Github teams permissions are configured correctly', $emoji($teamCheck)), '', ]); - $isCompliant &= $settingsCheck && $webhookCheck && $packagistCheck && $teamCheck; if ($format == 'ci') { unset($details['repo_config'], $details['packagist_config'], $details['teams']); } - (clone $table)->addRow($details)->render(); + $componentTable = (clone $table); + $componentTable->addRow($details)->render(); + + if (!($settingsCheck && $webhookCheck && $packagistCheck && $teamCheck)) { + $failed[] = $componentTable; + } + } + + if (count($failed) > 0) { + $output->writeln('ERROR: ' . count($failed) . ' components failed the repo compliance check:'); + foreach ($failed as $table) { + $table->render(); + } + return Command::FAILURE; } - return $isCompliant ? Command::SUCCESS : Command::FAILURE; + return Command::SUCCESS; } private function checkSettingsCompliance(array $details) diff --git a/dev/src/Command/RepoSplitCommand.php b/dev/src/Command/RepoSplitCommand.php index 461b85cf337..bea548652ac 100644 --- a/dev/src/Command/RepoSplitCommand.php +++ b/dev/src/Command/RepoSplitCommand.php @@ -23,13 +23,11 @@ use Google\Cloud\Dev\ReleaseNotes; use Google\Cloud\Dev\RunShell; use Google\Cloud\Dev\Split; -use Google\Cloud\Dev\SplitInstall; use GuzzleHttp\BodySummarizer; use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; diff --git a/dev/src/GitHub.php b/dev/src/GitHub.php index 356eab756cf..efde3bc3743 100644 --- a/dev/src/GitHub.php +++ b/dev/src/GitHub.php @@ -407,6 +407,9 @@ public function addWebhook( return $res->getStatusCode() === 201; } catch (\Exception $e) { + if (422 === $e->getCode()) { + return true; // webhook already exists! + } $this->logException($e); return false; }