Cleanup commands, prepare for features

This commit is contained in:
Christopher Vagnetoft
2026-08-26 00:54:59 +02:00
parent c30c04d1f9
commit 90f5af1c6b
10 changed files with 101 additions and 35 deletions
+3 -9
View File
@@ -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) {
+15
View File
@@ -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;
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace NoccyLabs\Composer\PackagePlugin\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Composer\Command\BaseCommand;
use NoccyLabs\Composer\PackagePlugin\Package\PackagePublisher;
use NoccyLabs\Composer\PackagePlugin\Project\ProjectInfo;
use NoccyLabs\Composer\PackagePlugin\Registry\Credentials\InsecureStore;
use NoccyLabs\Composer\PackagePlugin\Registry\Gitea\GiteaProvider;
use NoccyLabs\Composer\PackagePlugin\Registry\RegistryFactory;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class PackageListCommand extends PackageCommand
{
protected function configure(): void
{
$this
->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:",
"",
" <info>gitea:{server}</> - to query <info>server</> as the default user",
" <info>gitea:{server}:{owner}</> - to query <info>server</> as <info>owner</>",
""
]);
return self::INVALID;
}
return 0;
}
}
+1 -7
View File
@@ -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);
+1 -7
View File
@@ -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();
+1
View File
@@ -13,6 +13,7 @@ class CommandProvider implements CommandProviderCapability
new Command\PackageLoginCommand(),
new Command\PackagePublishCommand(),
new Command\PackageUnpublishCommand(),
new Command\PackageListCommand(),
];
}
}
+10 -4
View File
@@ -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);
}
}
}
+13 -3
View File
@@ -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;
}
}
}
+3 -3
View File
@@ -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;
}
}
}
+2 -2
View File
@@ -4,5 +4,5 @@ namespace NoccyLabs\Composer\PackagePlugin\Registry;
interface RegistryProviderInterface
{
public function createRegistry(array $params): RegistryInterface;
}
public function createRegistry(string $params): RegistryInterface;
}