Skip to content

Commit

Permalink
bug #80 Fetch funding links when needed + fail gracefully (nicolas-gr…
Browse files Browse the repository at this point in the history
…ekas)

This PR was merged into the 1.2-dev branch.

Discussion
----------

Fetch funding links when needed + fail gracefully

Closes #79

Commits
-------

59ec80b Fetch funding links when needed + fail gracefully
  • Loading branch information
nicolas-grekas committed Jan 15, 2020
2 parents 942514e + 59ec80b commit a8a5fbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Command/FundCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 11 additions & 4 deletions src/GitHubClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -196,19 +198,24 @@ 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]);
}
}
}

return $result['data'];
return isset($result['data']) ? $result['data'] : [];
}

private function getDirectlyRequiredPackageNames()
Expand Down

0 comments on commit a8a5fbe

Please sign in to comment.