diff --git a/src/Command/FundCommand.php b/src/Command/FundCommand.php index 28fcd46..5afdfe0 100644 --- a/src/Command/FundCommand.php +++ b/src/Command/FundCommand.php @@ -46,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $composer = $this->getComposer(); $gitHub = new GitHubClient($composer, $this->getIO()); - $repos = $gitHub->getRepositories($failures); + $repos = $gitHub->getRepositories($failures, true); $fundings = []; $notStarred = 0; diff --git a/src/GitHubClient.php b/src/GitHubClient.php index e38ec0b..2d0afeb 100644 --- a/src/GitHubClient.php +++ b/src/GitHubClient.php @@ -103,7 +103,7 @@ public function __construct(Composer $composer, IOInterface $io) $this->rfs = Factory::createRemoteFilesystem($io, $composer->getConfig()); } - public function getRepositories(array &$failures = null) + public function getRepositories(array &$failures = null, $withFundingLinks = false) { $repo = $this->composer->getRepositoryManager()->getLocalRepository(); @@ -144,7 +144,9 @@ public function getRepositories(array &$failures = null) ksort($urls); $i = 0; - $template = '_%d: repository(owner:"%s",name:"%s"){id,viewerHasStarred,fundingLinks{platform,url}}'."\n"; + $template = $withFundingLinks + ? '_%d: repository(owner:"%s",name:"%s"){id,viewerHasStarred,fundingLinks{platform,url}}'."\n" + : '_%d: repository(owner:"%s",name:"%s"){id,viewerHasStarred}'."\n"; $graphql = ''; foreach ($urls as $package => $url) { @@ -196,11 +198,16 @@ public function call($graphql, array &$failures = []) $result = json_decode($result, true); if (isset($result['errors'][0]['message'])) { - if (!$result['data']) { + if (!isset($result['data'])) { throw new TransportException($result['errors'][0]['message']); } foreach ($result['errors'] as $error) { + if (!isset($error['path'])) { + $failures[isset($error['type']) ? $error['type'] : $error['message']] = $error['message']; + continue; + } + foreach ($error['path'] as $path) { $failures += [$path => $error['message']]; unset($result['data'][$path]); @@ -208,7 +215,7 @@ public function call($graphql, array &$failures = []) } } - return $result['data']; + return isset($result['data']) ? $result['data'] : []; } private function getDirectlyRequiredPackageNames()