Retrieve latest funding info for all packages in fund command

main
Jordi Boggiano 4 years ago
parent 98af0fdf85
commit beb64914a3
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -14,6 +14,7 @@ namespace Composer\Command;
use Composer\Package\CompletePackageInterface; use Composer\Package\CompletePackageInterface;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Repository\CompositeRepository;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -36,20 +37,19 @@ class FundCommand extends BaseCommand
$composer = $this->getComposer(); $composer = $this->getComposer();
$repo = $composer->getRepositoryManager()->getLocalRepository(); $repo = $composer->getRepositoryManager()->getLocalRepository();
$remoteRepos = new CompositeRepository($composer->getRepositoryManager()->getRepositories());
$fundings = array(); $fundings = array();
foreach ($repo->getPackages() as $package) { foreach ($repo->getPackages() as $package) {
if ($package instanceof AliasPackage) { if ($package instanceof AliasPackage) {
continue; continue;
} }
if ($package instanceof CompletePackageInterface && $funding = $package->getFunding()) { $latest = $remoteRepos->findPackage($package->getName(), 'dev-master');
foreach ($funding as $fundingOption) { if ($latest instanceof CompletePackageInterface && $latest->getFunding()) {
list($vendor, $packageName) = explode('/', $package->getPrettyName()); $fundings = $this->insertFundingData($fundings, $latest);
$url = $fundingOption['url']; continue;
if (!empty($fundingOption['type']) && $fundingOption['type'] === 'github' && preg_match('{^https://github.com/([^/]+)$}', $url, $match)) {
$url = 'https://github.com/sponsors/'.$match[1];
}
$fundings[$vendor][$url][] = $packageName;
} }
if ($package instanceof CompletePackageInterface && $package->getFunding()) {
$fundings = $this->insertFundingData($fundings, $package);
} }
} }
@ -86,4 +86,18 @@ class FundCommand extends BaseCommand
return 0; return 0;
} }
private function insertFundingData(array $fundings, CompletePackageInterface $package)
{
foreach ($package->getFunding() as $fundingOption) {
list($vendor, $packageName) = explode('/', $package->getPrettyName());
$url = $fundingOption['url'];
if (!empty($fundingOption['type']) && $fundingOption['type'] === 'github' && preg_match('{^https://github.com/([^/]+)$}', $url, $match)) {
$url = 'https://github.com/sponsors/'.$match[1];
}
$fundings[$vendor][$url][] = $packageName;
}
return $fundings;
}
} }

Loading…
Cancel
Save