Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions dev/src/Command/RepoComplianceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>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)
Expand Down
2 changes: 0 additions & 2 deletions dev/src/Command/RepoSplitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions dev/src/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading