feat : add DeployProcessor for triggering deployments
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
47
src/State/DeployProcessor.php
Normal file
47
src/State/DeployProcessor.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\ApiResource\DeployResult;
|
||||
use App\Repository\EnvironmentRepository;
|
||||
use App\Service\DeployService;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
final readonly class DeployProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private EnvironmentRepository $environmentRepository,
|
||||
private DeployService $deployService,
|
||||
) {}
|
||||
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): DeployResult
|
||||
{
|
||||
$id = $uriVariables['id'] ?? null;
|
||||
$environment = $id ? $this->environmentRepository->find($id) : null;
|
||||
|
||||
if (null === $environment) {
|
||||
throw new NotFoundHttpException(sprintf('Environment "%s" not found.', $id));
|
||||
}
|
||||
|
||||
$requestData = $context['request']?->toArray() ?? [];
|
||||
$tag = $requestData['tag'] ?? null;
|
||||
|
||||
if (null === $tag || '' === $tag) {
|
||||
throw new BadRequestHttpException('The "tag" field is required.');
|
||||
}
|
||||
|
||||
$result = $this->deployService->deploy($environment, $tag);
|
||||
|
||||
$dto = new DeployResult();
|
||||
$dto->success = $result['success'];
|
||||
$dto->output = $result['output'];
|
||||
$dto->tag = $tag;
|
||||
|
||||
return $dto;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user