From d007ec23da27970a60796b8e643205133f747378 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Mon, 29 Dec 2025 00:44:02 +0100 Subject: [PATCH] Add unpublish support, curl cli support --- src/CommandProvider.php | 2 +- src/Registry/Gitea/GiteaRegistry.php | 42 ++++++++++++++++++---------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/CommandProvider.php b/src/CommandProvider.php index a1e2fbc..941acc4 100644 --- a/src/CommandProvider.php +++ b/src/CommandProvider.php @@ -12,7 +12,7 @@ class CommandProvider implements CommandProviderCapability new Command\PackageBuildCommand(), new Command\PackageLoginCommand(), new Command\PackagePublishCommand(), - // new Command\PackageUnpublishCommand(), + new Command\PackageUnpublishCommand(), ]; } } diff --git a/src/Registry/Gitea/GiteaRegistry.php b/src/Registry/Gitea/GiteaRegistry.php index 0c70aab..62e0a3d 100644 --- a/src/Registry/Gitea/GiteaRegistry.php +++ b/src/Registry/Gitea/GiteaRegistry.php @@ -24,20 +24,24 @@ class GiteaRegistry implements RegistryInterface public function unpublishPackageVersion(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/%s/%s", $this->server, $this->owner, urlencode($project->name), $project->version); $request = [ - 'method' => 'PUT', + 'method' => 'DELETE', 'url' => $url, 'auth' => $this->token, - 'filename' => $project->filename, ]; $this->invoke($request); - } public function unpublishPackage(ProjectInfo $project): void { - + $url = sprintf("https://%s/api/packages/%s/composer/%s", $this->server, $this->owner, urlencode($project->name)); + $request = [ + 'method' => 'DELETE', + 'url' => $url, + 'auth' => $this->token, + ]; + $this->invoke($request); } private function invoke(array $request): mixed @@ -62,12 +66,17 @@ class GiteaRegistry implements RegistryInterface curl_setopt($curl, CURLOPT_URL, $request['url']); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - if ($request['method'] === 'PUT') { - curl_setopt($curl, CURLOPT_PUT, 1); - curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($curl, CURLOPT_USERPWD, $this->token); - curl_setopt($curl, CURLOPT_INFILE, $fd); - curl_setopt($curl, CURLOPT_INFILESIZE, $fdlen); + switch ($request['method']) { + case 'PUT': + curl_setopt($curl, CURLOPT_PUT, 1); + curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($curl, CURLOPT_USERPWD, $this->token); + curl_setopt($curl, CURLOPT_INFILE, $fd); + curl_setopt($curl, CURLOPT_INFILESIZE, $fdlen); + break; + case 'DELETE': + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + break; } $response = curl_exec($curl); $code = curl_getinfo($curl, CURLINFO_RESPONSE_CODE); @@ -98,9 +107,14 @@ class GiteaRegistry implements RegistryInterface $cmd = trim(exec("which curl")); $args = [ "--user", $this->token ]; - if ($request['method'] === 'PUT') { - $args[] = '--upload-file'; - $args[] = $request['filename']; + switch ($request['method']) { + case 'PUT': + $args[] = '--upload-file'; + $args[] = $request['filename']; + break; + case 'DELETE': + $args[] = '-XDELETE'; + break; } $args[] = $request['url'];