From bcccebcac7f250f74079d83cf1c3199b319173b6 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 18 Jul 2024 01:24:18 +0400 Subject: [PATCH] Prove that Github API works --- src/Command/Get.php | 9 +++++++++ src/Module/Environment/Architecture.php | 2 +- src/Module/Environment/OperatingSystem.php | 12 ++++++------ src/Module/Repository/Internal/AssetsCollection.php | 6 ++---- .../Repository/Internal/GitHub/GitHubRepository.php | 2 +- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Command/Get.php b/src/Command/Get.php index 51cdc36..aadb790 100644 --- a/src/Command/Get.php +++ b/src/Command/Get.php @@ -8,6 +8,7 @@ use Internal\DLoad\Module\Environment\Architecture; use Internal\DLoad\Module\Environment\OperatingSystem; use Internal\DLoad\Module\Environment\Stability; +use Internal\DLoad\Module\Repository\Internal\GitHub\GitHubRepository; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\SignalableCommandInterface; @@ -83,6 +84,14 @@ protected function execute( $output->writeln('Operating system: ' . $container->get(OperatingSystem::class)->name); $output->writeln('Stability: ' . $container->get(Stability::class)->name); + + $repo = 'roadrunner-server/roadrunner'; + trap(GitHubRepository::fromDsn($repo)->getReleases()->first()->getAssets() + ->whereArchitecture($container->get(Architecture::class)) + ->whereOperatingSystem($container->get(OperatingSystem::class)) + ); + + return Command::SUCCESS; } } diff --git a/src/Module/Environment/Architecture.php b/src/Module/Environment/Architecture.php index 06c3921..0209e6d 100644 --- a/src/Module/Environment/Architecture.php +++ b/src/Module/Environment/Architecture.php @@ -41,7 +41,7 @@ public static function tryFromString(string $arch): ?self public static function tryFromBuildName(string $name): ?self { - if (\preg_match('/\b(amd64|arm64|aarch64|x86_64|x64|x86)\b/i', $name, $matches)) { + if (\preg_match('/\b(amd64|arm64|aarch64|x86_64|x64|x86)\b/i', $name, $matches) !== 1) { return null; } diff --git a/src/Module/Environment/OperatingSystem.php b/src/Module/Environment/OperatingSystem.php index 8e91287..09eaf50 100644 --- a/src/Module/Environment/OperatingSystem.php +++ b/src/Module/Environment/OperatingSystem.php @@ -35,11 +35,11 @@ public static function fromGlobals(): self public static function tryFromString(string $name): ?self { - return match ($name) { - 'Windows' => self::Windows, - 'BSD' => self::BSD, - 'Darwin' => self::Darwin, - 'Linux' => \str_contains(\PHP_OS, 'Alpine') + return match (\strtolower($name)) { + 'windows' => self::Windows, + 'bSD' => self::BSD, + 'darwin' => self::Darwin, + 'linux' => \str_contains(\PHP_OS, 'alpine') ? self::Alpine : self::Linux, default => null, @@ -48,7 +48,7 @@ public static function tryFromString(string $name): ?self public static function tryFromBuildName(string $name): ?self { - if (\preg_match('/\b(windows|linux|darwin|bsd|alpine)\b/i', $name, $matches)) { + if (\preg_match('/\b(windows|linux|darwin|alpine|bsd|freebsd)\b/i', $name, $matches) !== 1) { return null; } diff --git a/src/Module/Repository/Internal/AssetsCollection.php b/src/Module/Repository/Internal/AssetsCollection.php index 886ffee..47aa061 100644 --- a/src/Module/Repository/Internal/AssetsCollection.php +++ b/src/Module/Repository/Internal/AssetsCollection.php @@ -26,16 +26,14 @@ public function exceptDebPackages(): self public function whereArchitecture(Architecture $arch): self { return $this->filter( - static fn(AssetInterface $asset): bool => - \str_contains($asset->getName(), '-' . \strtolower($arch->name) . '.'), + static fn(AssetInterface $asset): bool => $asset->getArchitecture() === $arch, ); } public function whereOperatingSystem(OperatingSystem $os): self { return $this->filter( - static fn(AssetInterface $asset): bool => - \str_contains($asset->getName(), '-' . \strtolower($os->name) . '-'), + static fn(AssetInterface $asset): bool => $asset->getOperatingSystem() === $os, ); } } diff --git a/src/Module/Repository/Internal/GitHub/GitHubRepository.php b/src/Module/Repository/Internal/GitHub/GitHubRepository.php index 1ec383d..eeb86a0 100644 --- a/src/Module/Repository/Internal/GitHub/GitHubRepository.php +++ b/src/Module/Repository/Internal/GitHub/GitHubRepository.php @@ -55,7 +55,7 @@ public function __construct(string $owner, string $repository, HttpClientInterfa */ public static function fromDsn(string $package, HttpClientInterface $client = null): GitHubRepository { - [$owner, $name] = $package; + [$owner, $name] = explode('/', $package); return new GitHubRepository($owner, $name, $client); }