Retrieve funding info from github into composer.json if not declared there

main
Jordi Boggiano 4 years ago
parent 538f070a29
commit b033a2ae81
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -35,6 +35,7 @@ class GitHubDriver extends VcsDriver
protected $infoCache = array();
protected $isPrivate = false;
private $isArchived = false;
private $fundingInfo;
/**
* Git Driver
@ -166,6 +167,10 @@ class GitHubDriver extends VcsDriver
if (!isset($composer['abandoned']) && $this->isArchived) {
$composer['abandoned'] = true;
}
if (!isset($composer['funding']) && $funding = $this->getFundingInfo()) {
$composer['funding'] = $funding;
}
}
if ($this->shouldCache($identifier)) {
@ -178,6 +183,35 @@ class GitHubDriver extends VcsDriver
return $this->infoCache[$identifier];
}
private function getFundingInfo()
{
if (null !== $this->fundingInfo) {
return $this->fundingInfo;
}
if ($this->originUrl !== 'github.com') {
return $this->fundingInfo = false;
}
$graphql = 'query{repository(owner:"'.$this->owner.'",name:"'.$this->repository.'"){fundingLinks{platform,url}}}';
$result = $this->remoteFilesystem->getContents($this->originUrl, 'https://api.github.com/graphql', false, [
'http' => [
'method' => 'POST',
'content' => json_encode(['query' => $graphql]),
'header' => ['Content-Type: application/json'],
],
]);
$result = json_decode($result, true);
if (empty($result['data']['repository']['fundingLinks'])) {
return $this->fundingInfo = false;
}
return $this->fundingInfo = array_map(function ($link) {
return array('type' => strtolower($link['platform']), 'url' => $link['url']);
}, $result['data']['repository']['fundingLinks']);
}
/**
* {@inheritdoc}
*/

Loading…
Cancel
Save