Skip to content

Commit 408735e

Browse files
authored
chore(dev): repo compliance improvements (#9160)
* fix(dev): repo compliance skip * fix new package version number * Revert "fix new package version number" This reverts commit a914509. * make more readable * do not fail if webhook already exists
1 parent d34a41b commit 408735e

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

dev/src/Command/RepoComplianceCommand.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ protected function configure()
4646
{
4747
$this->setName('repo:compliance')
4848
->setDescription('ensure all github repositories meet compliance')
49-
->addOption('component', 'c', InputOption::VALUE_REQUIRED, 'If specified, display repo info for this component only', '')
50-
->addOption('token', 't', InputOption::VALUE_REQUIRED, 'Github token to use for authentication', '')
49+
->addOption(
50+
'component',
51+
'c',
52+
InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY,
53+
'If specified, display repo info for this component only'
54+
)
55+
->addOption('token', 't', InputOption::VALUE_REQUIRED, 'Github token to use for authentication')
5156
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'can be "ci" or "table"', 'table')
5257
->addOption('packagist-token', 'p', InputOption::VALUE_REQUIRED, 'Packagist token for the webhook')
5358
;
@@ -77,19 +82,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
7782
];
7883
(clone $table)->setHeaders($headers)->render();
7984

80-
$componentName = $input->getOption('component');
81-
$components = $componentName ? [new Component($componentName)] : Component::getComponents();
85+
$components = $input->getOption('component')
86+
? array_map(fn ($c) => new Component($c), $input->getOption('component'))
87+
: Component::getComponents();
8288

83-
$isCompliant = true;
8489
$emoji = fn ($check) => match ($check) { 'skipped' => '', false => '', true => '', null => ''};
90+
$failed = [];
8591
foreach ($components as $i => $component) {
8692
$isNewComponent = $component->getPackageVersion() === '0.0.0'
87-
|| $component->getPackageVersion() === '0.1.0' && $format == 'ci';
93+
|| ($component->getPackageVersion() === '0.1.0' && $format == 'ci');
8894

8995
do {
9096
$refreshDetails = false;
9197
if (!$details = $this->getRepoDetails($component)) {
92-
$isCompliant = $settingsCheck = $packagistCheck = $webhookCheck = $teamCheck = false;
98+
$settingsCheck = $packagistCheck = $webhookCheck = $teamCheck = false;
9399
$details = array_fill(0, count($headers) - 1, '**REPO NOT FOUND**');
94100
$details[0] = str_replace('googleapis/', '', $component->getRepoName());
95101
continue;
@@ -122,14 +128,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
122128
sprintf('%s Github teams permissions are configured correctly', $emoji($teamCheck)),
123129
'',
124130
]);
125-
$isCompliant &= $settingsCheck && $webhookCheck && $packagistCheck && $teamCheck;
126131
if ($format == 'ci') {
127132
unset($details['repo_config'], $details['packagist_config'], $details['teams']);
128133
}
129-
(clone $table)->addRow($details)->render();
134+
$componentTable = (clone $table);
135+
$componentTable->addRow($details)->render();
136+
137+
if (!($settingsCheck && $webhookCheck && $packagistCheck && $teamCheck)) {
138+
$failed[] = $componentTable;
139+
}
140+
}
141+
142+
if (count($failed) > 0) {
143+
$output->writeln('<error>ERROR: ' . count($failed) . ' components failed the repo compliance check:');
144+
foreach ($failed as $table) {
145+
$table->render();
146+
}
147+
return Command::FAILURE;
130148
}
131149

132-
return $isCompliant ? Command::SUCCESS : Command::FAILURE;
150+
return Command::SUCCESS;
133151
}
134152

135153
private function checkSettingsCompliance(array $details)

dev/src/Command/RepoSplitCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
use Google\Cloud\Dev\ReleaseNotes;
2424
use Google\Cloud\Dev\RunShell;
2525
use Google\Cloud\Dev\Split;
26-
use Google\Cloud\Dev\SplitInstall;
2726
use GuzzleHttp\BodySummarizer;
2827
use GuzzleHttp\Client;
2928
use GuzzleHttp\HandlerStack;
3029
use GuzzleHttp\Middleware;
3130
use Symfony\Component\Console\Command\Command;
32-
use Symfony\Component\Console\Input\ArrayInput;
3331
use Symfony\Component\Console\Input\InputArgument;
3432
use Symfony\Component\Console\Input\InputInterface;
3533
use Symfony\Component\Console\Input\InputOption;

dev/src/GitHub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ public function addWebhook(
407407

408408
return $res->getStatusCode() === 201;
409409
} catch (\Exception $e) {
410+
if (422 === $e->getCode()) {
411+
return true; // webhook already exists!
412+
}
410413
$this->logException($e);
411414
return false;
412415
}

0 commit comments

Comments
 (0)