@@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6666 }
6767
6868 $ table = (new Table ($ output ));
69- $ table ->setColumnWidths ([55 , 20 , 20 , 25 , 50 ]);
69+ $ table ->setColumnWidths ([55 , 20 , 22 , 33 , 50 ]);
7070 $ table ->setStyle ('compact ' );
7171 $ headers = $ format == 'ci ' ? ['Name ' , 'Compliance ' ] : [
7272 'Name ' ,
@@ -81,38 +81,47 @@ protected function execute(InputInterface $input, OutputInterface $output)
8181 $ components = $ componentName ? [new Component ($ componentName )] : Component::getComponents ();
8282
8383 $ isCompliant = true ;
84+ $ emoji = fn ($ check ) => match ($ check ) { 'skipped ' => '⚪ ' , false => '❌ ' , true => '✅ ' , null => '❓ ' };
8485 foreach ($ components as $ i => $ component ) {
86+ $ isNewComponent = $ component ->getPackageVersion () === '0.0.0 '
87+ || $ component ->getPackageVersion () === '0.1.0 ' && $ format == 'ci ' ;
88+
8589 do {
86- $ details = $ this ->getRepoDetails ($ component );
87- $ settingsCheck = $ packagistCheck = $ webhookCheck = $ teamCheck = true ;
8890 $ refreshDetails = false ;
91+ if (!$ details = $ this ->getRepoDetails ($ component )) {
92+ $ isCompliant = $ settingsCheck = $ packagistCheck = $ webhookCheck = $ teamCheck = false ;
93+ $ details = array_fill (0 , count ($ headers ) - 1 , '**REPO NOT FOUND** ' );
94+ $ details [0 ] = str_replace ('googleapis/ ' , '' , $ component ->getRepoName ());
95+ continue ;
96+ }
97+ $ settingsCheck = $ packagistCheck = $ webhookCheck = $ teamCheck = true ;
8998 if (!$ this ->checkSettingsCompliance ($ details )) {
9099 $ settingsCheck = false ;
91100 $ refreshDetails |= $ this ->askFixSettingsCompliance ($ input , $ output , $ details );
92101 }
93102 if (!$ this ->checkWebhookCompliance ($ details )) {
94- $ webhookCheck = false ;
103+ $ webhookCheck = $ this -> github -> token ? ( $ isNewComponent ? ' skipped ' : false ) : null ;
95104 $ refreshDetails |= $ this ->askFixWebhookCompliance ($ input , $ output , $ details );
96105 }
97106 if (!$ this ->checkPackagistCompliance ($ details )) {
98- $ packagistCheck = false ;
99- $ refreshDetails |= $ this ->askFixPackagistCompliance ($ input , $ output , $ component ->getRepoName ());
107+ // New components don't have packagist config, so bypass for CI.
108+ $ packagistCheck = $ isNewComponent ? 'skipped ' : false ;
109+ $ refreshDetails |= $ this ->askFixPackagistCompliance ($ input , $ output , $ details );
110+ $ details ['packagist_config ' ] ??= '**PACKAGE NOT FOUND** ' ;
100111 }
101112 if (!$ this ->checkTeamCompliance ($ details )) {
102113 $ teamCheck = $ this ->github ->token ? false : null ;
103114 $ refreshDetails |= $ this ->askFixTeamCompliance ($ input , $ output , $ component ->getRepoName ());
104115 }
105116 } while ($ refreshDetails );
106117
107- $ emoji = fn (?bool $ check ) => match ($ check ) { null => '❓ ' , true => '✅ ' , false => '❌ ' };
108118 $ details ['compliant ' ] = implode ("\n" , [
109119 sprintf ('%s Issues, Projects, Wiki, Pages, and Discussion are disabled ' , $ emoji ($ settingsCheck )),
110120 sprintf ('%s Packagist webhook is configured ' , $ emoji ($ webhookCheck )),
111121 sprintf ('%s Packagist maintainer is "google-cloud" ' , $ emoji ($ packagistCheck )),
112122 sprintf ('%s Github teams permissions are configured correctly ' , $ emoji ($ teamCheck )),
113123 '' ,
114124 ]);
115-
116125 $ isCompliant &= $ settingsCheck && $ webhookCheck && $ packagistCheck && $ teamCheck ;
117126 if ($ format == 'ci ' ) {
118127 unset($ details ['repo_config ' ], $ details ['packagist_config ' ], $ details ['teams ' ]);
@@ -169,6 +178,10 @@ private function askFixSettingsCompliance(InputInterface $input, OutputInterface
169178
170179 private function checkWebhookCompliance (array $ details ): bool
171180 {
181+ if (!$ this ->github ->token ) {
182+ return false ;
183+ }
184+
172185 $ repoName = 'googleapis/ ' . $ details ['name ' ];
173186 $ webhookUrl = $ this ->packagist ->getWebhookUrl ();
174187
@@ -208,15 +221,15 @@ private function askFixWebhookCompliance(InputInterface $input, OutputInterface
208221 private function checkPackagistCompliance (array $ details )
209222 {
210223 return !empty (array_filter (
211- explode ("\n" , $ details ['packagist_config ' ]),
224+ explode ("\n" , ( string ) $ details ['packagist_config ' ]),
212225 fn ($ team ) => $ team === self ::PACKAGIST_USERNAME
213226 ));
214227 }
215228
216229 private function askFixPackagistCompliance (InputInterface $ input , OutputInterface $ output , array $ details )
217230 {
218- if (!$ this ->github ->token || $ input ->getOption ('format ' ) == 'ci ' ) {
219- // without a token, or in CI mode, don't ask to fix compliance
231+ if (!$ this ->github ->token || $ input ->getOption ('format ' ) == 'ci ' || $ details [ ' packagist_config ' ] === null ) {
232+ // cannot fix compliance without a token, or in CI mode, or without packagist config
220233 return false ;
221234 }
222235 throw new \Exception ('not implemented ' );
@@ -239,9 +252,16 @@ private function askFixTeamCompliance(InputInterface $input, OutputInterface $ou
239252 return false ;
240253 }
241254
242- private function getRepoDetails (Component $ component ): array
255+ private function getRepoDetails (Component $ component ): array | null
243256 {
244- $ repoDetails = (array ) $ this ->github ->getRepoDetails ($ component ->getRepoName ());
257+ if (!$ repoDetails = $ this ->github ->getRepoDetails ($ component ->getRepoName ())) {
258+ return null ;
259+ }
260+
261+ if (null !== $ packagistDetails = $ this ->packagist ->getMaintainers ($ component ->getPackageName ())) {
262+ $ packagistDetails = implode ("\n" , $ packagistDetails );
263+ }
264+
245265 // use "array_intersect_key" to filter out fields that were not requested.
246266 $ fields = array_map (
247267 fn ($ field ) => var_export ($ field , true ),
@@ -258,7 +278,7 @@ private function getRepoDetails(Component $component): array
258278 $ fields ,
259279 array_keys ($ fields ),
260280 )),
261- 'packagist_config ' => implode ( "\n" , $ this -> packagist -> getMaintainers ( $ component -> getPackageName ())) ,
281+ 'packagist_config ' => $ packagistDetails ,
262282 'teams ' => $ this ->getRepoTeamDetails ($ component ),
263283 ];
264284 }
0 commit comments