From 90f5af1c6bdd08af205eeecacba5288dfb56d108 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Wed, 26 Aug 2026 00:54:59 +0200 Subject: [PATCH] Cleanup commands, prepare for features --- src/Command/PackageBuildCommand.php | 12 ++--- src/Command/PackageCommand.php | 15 +++++++ src/Command/PackageListCommand.php | 52 ++++++++++++++++++++++ src/Command/PackagePublishCommand.php | 8 +--- src/Command/PackageUnpublishCommand.php | 8 +--- src/CommandProvider.php | 1 + src/Registry/Gitea/GiteaProvider.php | 14 ++++-- src/Registry/Gitea/GiteaRegistry.php | 16 +++++-- src/Registry/RegistryFactory.php | 6 +-- src/Registry/RegistryProviderInterface.php | 4 +- 10 files changed, 101 insertions(+), 35 deletions(-) create mode 100644 src/Command/PackageListCommand.php diff --git a/src/Command/PackageBuildCommand.php b/src/Command/PackageBuildCommand.php index 079418d..64be7a9 100644 --- a/src/Command/PackageBuildCommand.php +++ b/src/Command/PackageBuildCommand.php @@ -21,9 +21,9 @@ class PackageBuildCommand extends PackageCommand $this ->setName('package:build') ->setAliases([ "package" ]) - ->setDescription("Package the library into a zipball, or publish directly") + ->setDescription("Package the library into a zipball") ->addOption("publish", null, InputOption::VALUE_REQUIRED, "Publish to registry immediately after building") - ->addOption("rm", null, InputOption::VALUE_NONE, "With --publish: remove the .zip after publishing") + ->addOption("rm", null, InputOption::VALUE_NONE, "With --publish remove the .zip after publishing") ->addOption("dirty", null, InputOption::VALUE_NONE, "Build directly from source without cloning") ->addOption("force", null, InputOption::VALUE_NONE, "Build even if the output file already exists") ->addArgument("version", InputArgument::OPTIONAL, "The tag to build (default is latest tag)") @@ -48,13 +48,7 @@ class PackageBuildCommand extends PackageCommand } if ($registry) { - $credentials = $this->getCredentialsStore(); - - $providers = [ - 'gitea' => new GiteaProvider($credentials) - ]; - - $factory = new RegistryFactory($providers); + $factory = $this->getRegistryFactory(); $publisher = new PackagePublisher($factory, $output); if (!$registry) { diff --git a/src/Command/PackageCommand.php b/src/Command/PackageCommand.php index 1e719f3..39086d3 100644 --- a/src/Command/PackageCommand.php +++ b/src/Command/PackageCommand.php @@ -11,6 +11,7 @@ use NoccyLabs\Composer\PackagePlugin\Project\ProjectInfo; use NoccyLabs\Composer\PackagePlugin\Registry\Credentials\InsecureStore; use NoccyLabs\Composer\PackagePlugin\Registry\Credentials\StoreInterface; use NoccyLabs\Composer\PackagePlugin\Registry\Gitea\GiteaProvider; +use NoccyLabs\Composer\PackagePlugin\Registry\Packagist\PackagistProvider; use NoccyLabs\Composer\PackagePlugin\Registry\RegistryFactory; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -23,4 +24,18 @@ abstract class PackageCommand extends BaseCommand return new InsecureStore(); } + public function getRegistryFactory(): RegistryFactory + { + $credentials = $this->getCredentialsStore(); + + $providers = [ + 'gitea' => new GiteaProvider($credentials), + // 'packagist' => new PackagistProvider($credentials), + ]; + + $factory = new RegistryFactory($providers); + + return $factory; + } + } diff --git a/src/Command/PackageListCommand.php b/src/Command/PackageListCommand.php new file mode 100644 index 0000000..786034c --- /dev/null +++ b/src/Command/PackageListCommand.php @@ -0,0 +1,52 @@ +setName('package:list') + ->setDescription("List published package versions") + ->addArgument("registry", InputArgument::OPTIONAL, "The registry to query") + ; + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $registry = $input->getArgument("registry"); + //$version = $input->getArgument("version"); + + $factory = $this->getRegistryFactory(); + $publisher = new PackagePublisher($factory, $output); + + //$project = ProjectInfo::read(version: $version); + + if (!$registry) { + $output->writeln([ + "Missing registry to query. Please specify the registry like this:", + "", + " gitea:{server} - to query server as the default user", + " gitea:{server}:{owner} - to query server as owner", + "" + ]); + return self::INVALID; + } + + + + return 0; + } +} diff --git a/src/Command/PackagePublishCommand.php b/src/Command/PackagePublishCommand.php index 88adfbf..6f071ab 100644 --- a/src/Command/PackagePublishCommand.php +++ b/src/Command/PackagePublishCommand.php @@ -27,16 +27,10 @@ class PackagePublishCommand extends PackageCommand protected function execute(InputInterface $input, OutputInterface $output): int { - $credentials = $this->getCredentialsStore(); - $registry = $input->getArgument("registry"); $version = $input->getArgument("version"); - $providers = [ - 'gitea' => new GiteaProvider($credentials) - ]; - - $factory = new RegistryFactory($providers); + $factory = $this->getRegistryFactory(); $publisher = new PackagePublisher($factory, $output); $project = ProjectInfo::read(version: $version); diff --git a/src/Command/PackageUnpublishCommand.php b/src/Command/PackageUnpublishCommand.php index 23e181f..2dca67f 100644 --- a/src/Command/PackageUnpublishCommand.php +++ b/src/Command/PackageUnpublishCommand.php @@ -28,13 +28,7 @@ class PackageUnpublishCommand extends PackageCommand protected function execute(InputInterface $input, OutputInterface $output): int { - $credentials = $this->getCredentialsStore(); - - $providers = [ - 'gitea' => new GiteaProvider($credentials) - ]; - - $factory = new RegistryFactory($providers); + $factory = $this->getRegistryFactory(); $publisher = new PackagePublisher($factory, $output); $project = ProjectInfo::read(); diff --git a/src/CommandProvider.php b/src/CommandProvider.php index 941acc4..127869e 100644 --- a/src/CommandProvider.php +++ b/src/CommandProvider.php @@ -13,6 +13,7 @@ class CommandProvider implements CommandProviderCapability new Command\PackageLoginCommand(), new Command\PackagePublishCommand(), new Command\PackageUnpublishCommand(), + new Command\PackageListCommand(), ]; } } diff --git a/src/Registry/Gitea/GiteaProvider.php b/src/Registry/Gitea/GiteaProvider.php index df8f5ef..26efcf0 100644 --- a/src/Registry/Gitea/GiteaProvider.php +++ b/src/Registry/Gitea/GiteaProvider.php @@ -10,12 +10,18 @@ class GiteaProvider implements RegistryProviderInterface { use ProviderTrait; - public function createRegistry(array $params): RegistryInterface + public function createRegistry(string $params): RegistryInterface { - $server = array_shift($params); - $owner = array_shift($params); + if (str_contains("/", $params)) { + [$server,$owner] = explode("/", $params, 2); + } elseif (str_contains(":", $params)) { + [$server,$owner] = explode(":", $params, 2); + } else { + $server = $params; + $owner = null; + } $token = $this->credentials->getToken($server, $owner); [$user, $_] = explode(":", $token, 2); return new GiteaRegistry($server, $owner??$user, $token); } -} \ No newline at end of file +} diff --git a/src/Registry/Gitea/GiteaRegistry.php b/src/Registry/Gitea/GiteaRegistry.php index 62e0a3d..2bc978b 100644 --- a/src/Registry/Gitea/GiteaRegistry.php +++ b/src/Registry/Gitea/GiteaRegistry.php @@ -10,6 +10,14 @@ class GiteaRegistry implements RegistryInterface { use RegistryTrait; + public function listPackages(): array + { + } + + public function listPackageVersions(ProjectInfo $project): array + { + } + public function publishPackageVersion(ProjectInfo $project): void { $url = sprintf("https://%s/api/packages/%s/composer?version=%s", $this->server, $this->owner, $project->version); @@ -59,8 +67,10 @@ class GiteaRegistry implements RegistryInterface */ private function invokeExt(array $request): mixed { - $fd = fopen($request['filename'], "rb"); - $fdlen = filesize($request['filename']); + if (isset($reuest['filename'])) { + $fd = fopen($request['filename'], "rb"); + $fdlen = filesize($request['filename']); + } $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $request['url']); @@ -124,4 +134,4 @@ class GiteaRegistry implements RegistryInterface return true; } -} \ No newline at end of file +} diff --git a/src/Registry/RegistryFactory.php b/src/Registry/RegistryFactory.php index 0b47397..9b36bff 100644 --- a/src/Registry/RegistryFactory.php +++ b/src/Registry/RegistryFactory.php @@ -23,12 +23,12 @@ class RegistryFactory public function createRegistryFromUri(string $uri): RegistryInterface { - $params = explode(":", $uri); - $type = array_shift($params); + [$type, $params] = explode(":", $uri, 2); + // $type = array_shift($params); if (!isset($this->providers[$type])) { throw new \Exception("Invalid registry provider type '{$type}'. Supported are ".join(", ",array_keys($this->providers))); } $registry = $this->providers[$type]->createRegistry($params); return $registry; } -} \ No newline at end of file +} diff --git a/src/Registry/RegistryProviderInterface.php b/src/Registry/RegistryProviderInterface.php index 33684c7..f737829 100644 --- a/src/Registry/RegistryProviderInterface.php +++ b/src/Registry/RegistryProviderInterface.php @@ -4,5 +4,5 @@ namespace NoccyLabs\Composer\PackagePlugin\Registry; interface RegistryProviderInterface { - public function createRegistry(array $params): RegistryInterface; -} \ No newline at end of file + public function createRegistry(string $params): RegistryInterface; +}