1919
2020use Google \Cloud \Dev \Component ;
2121use Google \Cloud \Dev \GitHub ;
22+ use Google \Cloud \Dev \Packagist ;
2223use Google \Cloud \Dev \RunShell ;
2324use Symfony \Component \Console \Command \Command ;
2425use Symfony \Component \Console \Helper \Table ;
3637class RepoInfoCommand extends Command
3738{
3839 private GitHub $ github ;
40+ private Packagist $ packagist ;
3941
40- private static $ allFields = [
41- 'name ' => 'Name ' ,
42- 'has_issues ' => 'Has Issues ' ,
43- 'has_projects ' => 'Has Projects ' ,
44- 'has_wiki ' => 'Has Wiki ' ,
45- 'has_pages ' => 'Has Pages ' ,
46- 'has_discussions ' => 'Has Discussions ' ,
47- 'teams ' => 'Teams ' ,
48- ];
4942 protected function configure ()
5043 {
5144 $ this ->setName ('repo-info ' )
@@ -61,10 +54,17 @@ protected function configure()
6154 protected function execute (InputInterface $ input , OutputInterface $ output )
6255 {
6356 // Create github client wrapper
64- $ this ->github = new GitHub (new RunShell (), new Client (), $ input ->getOption ('token ' ), $ output );
57+ $ http = new Client ();
58+ $ this ->github = new GitHub (new RunShell (), $ http , $ input ->getOption ('token ' ), $ output );
59+ $ this ->packagist = new Packagist ($ http , '' , '' );
6560
6661 $ nextPageQuestion = new ConfirmationQuestion ('Next Page (enter) ' , true );
67- $ table = (new Table ($ output ))->setHeaders (self ::$ allFields );
62+ $ table = (new Table ($ output ))->setHeaders ([
63+ 'name ' => 'Name ' ,
64+ 'repo_config ' => 'Repo Config ' ,
65+ 'packagist_config ' => 'Packagist Config ' ,
66+ 'teams ' => 'Teams ' ,
67+ ]);
6868 if ($ componentName = $ input ->getArgument ('component ' )) {
6969 $ table ->setVertical ();
7070 }
@@ -92,6 +92,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
9292 if (!$ this ->checkSettingsCompliance ($ details )) {
9393 $ refreshDetails |= $ this ->askFixSettingsCompliance ($ input , $ output , $ details );
9494 }
95+ if (!$ this ->checkPackagistCompliance ($ details )) {
96+ $ refreshDetails |= $ this ->askFixPackagistCompliance ($ input , $ output , $ component ->getRepoName ());
97+ }
9598 if (!$ this ->checkTeamCompliance ($ details )) {
9699 $ refreshDetails |= $ this ->askFixTeamCompliance ($ input , $ output , $ component ->getRepoName ());
97100 }
@@ -141,6 +144,19 @@ private function askFixSettingsCompliance(InputInterface $input, OutputInterface
141144 return false ;
142145 }
143146
147+ private function checkPackagistCompliance (array $ details )
148+ {
149+ return !empty (array_filter (
150+ explode ("\n" , $ details ['packagist_config ' ]),
151+ fn ($ team ) => $ team === 'google-cloud '
152+ ));
153+ }
154+
155+ private function askFixPackagistCompliance (InputInterface $ input , OutputInterface $ output , array $ details )
156+ {
157+ throw new \Exception ('not implemented ' );
158+ }
159+
144160 private function askFixTeamCompliance (InputInterface $ input , OutputInterface $ output , string $ repoName )
145161 {
146162 $ question = new ConfirmationQuestion (sprintf (
@@ -155,18 +171,26 @@ private function askFixTeamCompliance(InputInterface $input, OutputInterface $ou
155171
156172 private function getRepoDetails (Component $ component ): array
157173 {
174+ $ repoDetails = (array ) $ this ->github ->getRepoDetails ($ component ->getRepoName ());
158175 // use "array_intersect_key" to filter out fields that were not requested.
159176 $ fields = array_map (
160- fn ($ field ) => is_bool ( $ field ) ? var_export ($ field , true ) : $ field ,
177+ fn ($ field ) => var_export ($ field , true ),
161178 array_intersect_key (
162- ( array ) $ this -> github -> getRepoDetails ( $ component -> getRepoName ()) ,
163- self :: $ allFields
179+ $ repoDetails ,
180+ array_flip ([ ' has_issues ' , ' has_projects ' , ' has_wiki ' , ' has_pages ' , ' has_discussions ' ])
164181 )
165182 );
166183
167- $ fields ['teams ' ] = $ this ->getRepoTeamDetails ($ component );
168-
169- return $ fields ;
184+ return [
185+ 'name ' => $ repoDetails ['name ' ],
186+ 'repo_config ' => implode ("\n" , array_map (
187+ fn ($ v , $ k ) => sprintf ('%s: %s ' , str_replace ('has_ ' , '' , $ k ), $ v ),
188+ $ fields ,
189+ array_keys ($ fields ),
190+ )),
191+ 'packagist_config ' => implode ("\n" , $ this ->packagist ->getMaintainers ($ component ->getPackageName ())),
192+ 'teams ' => $ this ->getRepoTeamDetails ($ component ),
193+ ];
170194 }
171195
172196 private function getRepoTeamDetails (Component $ component )
0 commit comments