Add unpublish support, curl cli support
This commit is contained in:
@@ -12,7 +12,7 @@ class CommandProvider implements CommandProviderCapability
|
|||||||
new Command\PackageBuildCommand(),
|
new Command\PackageBuildCommand(),
|
||||||
new Command\PackageLoginCommand(),
|
new Command\PackageLoginCommand(),
|
||||||
new Command\PackagePublishCommand(),
|
new Command\PackagePublishCommand(),
|
||||||
// new Command\PackageUnpublishCommand(),
|
new Command\PackageUnpublishCommand(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,20 +24,24 @@ class GiteaRegistry implements RegistryInterface
|
|||||||
|
|
||||||
public function unpublishPackageVersion(ProjectInfo $project): void
|
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 = [
|
$request = [
|
||||||
'method' => 'PUT',
|
'method' => 'DELETE',
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'auth' => $this->token,
|
'auth' => $this->token,
|
||||||
'filename' => $project->filename,
|
|
||||||
];
|
];
|
||||||
$this->invoke($request);
|
$this->invoke($request);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unpublishPackage(ProjectInfo $project): void
|
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
|
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_URL, $request['url']);
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
if ($request['method'] === 'PUT') {
|
switch ($request['method']) {
|
||||||
|
case 'PUT':
|
||||||
curl_setopt($curl, CURLOPT_PUT, 1);
|
curl_setopt($curl, CURLOPT_PUT, 1);
|
||||||
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||||
curl_setopt($curl, CURLOPT_USERPWD, $this->token);
|
curl_setopt($curl, CURLOPT_USERPWD, $this->token);
|
||||||
curl_setopt($curl, CURLOPT_INFILE, $fd);
|
curl_setopt($curl, CURLOPT_INFILE, $fd);
|
||||||
curl_setopt($curl, CURLOPT_INFILESIZE, $fdlen);
|
curl_setopt($curl, CURLOPT_INFILESIZE, $fdlen);
|
||||||
|
break;
|
||||||
|
case 'DELETE':
|
||||||
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$response = curl_exec($curl);
|
$response = curl_exec($curl);
|
||||||
$code = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
|
$code = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
|
||||||
@@ -98,9 +107,14 @@ class GiteaRegistry implements RegistryInterface
|
|||||||
$cmd = trim(exec("which curl"));
|
$cmd = trim(exec("which curl"));
|
||||||
$args = [ "--user", $this->token ];
|
$args = [ "--user", $this->token ];
|
||||||
|
|
||||||
if ($request['method'] === 'PUT') {
|
switch ($request['method']) {
|
||||||
|
case 'PUT':
|
||||||
$args[] = '--upload-file';
|
$args[] = '--upload-file';
|
||||||
$args[] = $request['filename'];
|
$args[] = $request['filename'];
|
||||||
|
break;
|
||||||
|
case 'DELETE':
|
||||||
|
$args[] = '-XDELETE';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$args[] = $request['url'];
|
$args[] = $request['url'];
|
||||||
|
|||||||
Reference in New Issue
Block a user