Skip to content

Commit

Permalink
Prove that Github API works
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jul 17, 2024
1 parent a055027 commit bcccebc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/Command/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Module/Environment/Architecture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Module/Environment/OperatingSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down
6 changes: 2 additions & 4 deletions src/Module/Repository/Internal/AssetsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
2 changes: 1 addition & 1 deletion src/Module/Repository/Internal/GitHub/GitHubRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit bcccebc

Please sign in to comment.