Cleanup commands, prepare for features
This commit is contained in:
@@ -21,9 +21,9 @@ class PackageBuildCommand extends PackageCommand
|
|||||||
$this
|
$this
|
||||||
->setName('package:build')
|
->setName('package:build')
|
||||||
->setAliases([ "package" ])
|
->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("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("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")
|
->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)")
|
->addArgument("version", InputArgument::OPTIONAL, "The tag to build (default is latest tag)")
|
||||||
@@ -48,13 +48,7 @@ class PackageBuildCommand extends PackageCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($registry) {
|
if ($registry) {
|
||||||
$credentials = $this->getCredentialsStore();
|
$factory = $this->getRegistryFactory();
|
||||||
|
|
||||||
$providers = [
|
|
||||||
'gitea' => new GiteaProvider($credentials)
|
|
||||||
];
|
|
||||||
|
|
||||||
$factory = new RegistryFactory($providers);
|
|
||||||
$publisher = new PackagePublisher($factory, $output);
|
$publisher = new PackagePublisher($factory, $output);
|
||||||
|
|
||||||
if (!$registry) {
|
if (!$registry) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use NoccyLabs\Composer\PackagePlugin\Project\ProjectInfo;
|
|||||||
use NoccyLabs\Composer\PackagePlugin\Registry\Credentials\InsecureStore;
|
use NoccyLabs\Composer\PackagePlugin\Registry\Credentials\InsecureStore;
|
||||||
use NoccyLabs\Composer\PackagePlugin\Registry\Credentials\StoreInterface;
|
use NoccyLabs\Composer\PackagePlugin\Registry\Credentials\StoreInterface;
|
||||||
use NoccyLabs\Composer\PackagePlugin\Registry\Gitea\GiteaProvider;
|
use NoccyLabs\Composer\PackagePlugin\Registry\Gitea\GiteaProvider;
|
||||||
|
use NoccyLabs\Composer\PackagePlugin\Registry\Packagist\PackagistProvider;
|
||||||
use NoccyLabs\Composer\PackagePlugin\Registry\RegistryFactory;
|
use NoccyLabs\Composer\PackagePlugin\Registry\RegistryFactory;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
@@ -23,4 +24,18 @@ abstract class PackageCommand extends BaseCommand
|
|||||||
return new InsecureStore();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,16 +27,10 @@ class PackagePublishCommand extends PackageCommand
|
|||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$credentials = $this->getCredentialsStore();
|
|
||||||
|
|
||||||
$registry = $input->getArgument("registry");
|
$registry = $input->getArgument("registry");
|
||||||
$version = $input->getArgument("version");
|
$version = $input->getArgument("version");
|
||||||
|
|
||||||
$providers = [
|
$factory = $this->getRegistryFactory();
|
||||||
'gitea' => new GiteaProvider($credentials)
|
|
||||||
];
|
|
||||||
|
|
||||||
$factory = new RegistryFactory($providers);
|
|
||||||
$publisher = new PackagePublisher($factory, $output);
|
$publisher = new PackagePublisher($factory, $output);
|
||||||
|
|
||||||
$project = ProjectInfo::read(version: $version);
|
$project = ProjectInfo::read(version: $version);
|
||||||
|
|||||||
@@ -28,13 +28,7 @@ class PackageUnpublishCommand extends PackageCommand
|
|||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$credentials = $this->getCredentialsStore();
|
$factory = $this->getRegistryFactory();
|
||||||
|
|
||||||
$providers = [
|
|
||||||
'gitea' => new GiteaProvider($credentials)
|
|
||||||
];
|
|
||||||
|
|
||||||
$factory = new RegistryFactory($providers);
|
|
||||||
$publisher = new PackagePublisher($factory, $output);
|
$publisher = new PackagePublisher($factory, $output);
|
||||||
|
|
||||||
$project = ProjectInfo::read();
|
$project = ProjectInfo::read();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class CommandProvider implements CommandProviderCapability
|
|||||||
new Command\PackageLoginCommand(),
|
new Command\PackageLoginCommand(),
|
||||||
new Command\PackagePublishCommand(),
|
new Command\PackagePublishCommand(),
|
||||||
new Command\PackageUnpublishCommand(),
|
new Command\PackageUnpublishCommand(),
|
||||||
|
new Command\PackageListCommand(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,16 @@ class GiteaProvider implements RegistryProviderInterface
|
|||||||
{
|
{
|
||||||
use ProviderTrait;
|
use ProviderTrait;
|
||||||
|
|
||||||
public function createRegistry(array $params): RegistryInterface
|
public function createRegistry(string $params): RegistryInterface
|
||||||
{
|
{
|
||||||
$server = array_shift($params);
|
if (str_contains("/", $params)) {
|
||||||
$owner = array_shift($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);
|
$token = $this->credentials->getToken($server, $owner);
|
||||||
[$user, $_] = explode(":", $token, 2);
|
[$user, $_] = explode(":", $token, 2);
|
||||||
return new GiteaRegistry($server, $owner??$user, $token);
|
return new GiteaRegistry($server, $owner??$user, $token);
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ class GiteaRegistry implements RegistryInterface
|
|||||||
{
|
{
|
||||||
use RegistryTrait;
|
use RegistryTrait;
|
||||||
|
|
||||||
|
public function listPackages(): array
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listPackageVersions(ProjectInfo $project): array
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function publishPackageVersion(ProjectInfo $project): void
|
public function publishPackageVersion(ProjectInfo $project): void
|
||||||
{
|
{
|
||||||
$url = sprintf("https://%s/api/packages/%s/composer?version=%s", $this->server, $this->owner, $project->version);
|
$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
|
private function invokeExt(array $request): mixed
|
||||||
{
|
{
|
||||||
|
if (isset($reuest['filename'])) {
|
||||||
$fd = fopen($request['filename'], "rb");
|
$fd = fopen($request['filename'], "rb");
|
||||||
$fdlen = filesize($request['filename']);
|
$fdlen = filesize($request['filename']);
|
||||||
|
}
|
||||||
|
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
curl_setopt($curl, CURLOPT_URL, $request['url']);
|
curl_setopt($curl, CURLOPT_URL, $request['url']);
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ class RegistryFactory
|
|||||||
|
|
||||||
public function createRegistryFromUri(string $uri): RegistryInterface
|
public function createRegistryFromUri(string $uri): RegistryInterface
|
||||||
{
|
{
|
||||||
$params = explode(":", $uri);
|
[$type, $params] = explode(":", $uri, 2);
|
||||||
$type = array_shift($params);
|
// $type = array_shift($params);
|
||||||
if (!isset($this->providers[$type])) {
|
if (!isset($this->providers[$type])) {
|
||||||
throw new \Exception("Invalid registry provider type '{$type}'. Supported are ".join(", ",array_keys($this->providers)));
|
throw new \Exception("Invalid registry provider type '{$type}'. Supported are ".join(", ",array_keys($this->providers)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ namespace NoccyLabs\Composer\PackagePlugin\Registry;
|
|||||||
|
|
||||||
interface RegistryProviderInterface
|
interface RegistryProviderInterface
|
||||||
{
|
{
|
||||||
public function createRegistry(array $params): RegistryInterface;
|
public function createRegistry(string $params): RegistryInterface;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user