1
0
Fork 0

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

pull/8453/head
Jordi Boggiano 2020-02-14 10:55:22 +01:00
parent 538f070a29
commit b033a2ae81
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 34 additions and 0 deletions

View File

@ -35,6 +35,7 @@ class GitHubDriver extends VcsDriver
protected $infoCache = array(); protected $infoCache = array();
protected $isPrivate = false; protected $isPrivate = false;
private $isArchived = false; private $isArchived = false;
private $fundingInfo;
/** /**
* Git Driver * Git Driver
@ -166,6 +167,10 @@ class GitHubDriver extends VcsDriver
if (!isset($composer['abandoned']) && $this->isArchived) { if (!isset($composer['abandoned']) && $this->isArchived) {
$composer['abandoned'] = true; $composer['abandoned'] = true;
} }
if (!isset($composer['funding']) && $funding = $this->getFundingInfo()) {
$composer['funding'] = $funding;
}
} }
if ($this->shouldCache($identifier)) { if ($this->shouldCache($identifier)) {
@ -178,6 +183,35 @@ class GitHubDriver extends VcsDriver
return $this->infoCache[$identifier]; 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} * {@inheritdoc}
*/ */