Retrieve funding info from github into composer.json if not declared there
parent
538f070a29
commit
b033a2ae81
|
@ -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}
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue