refs #2462. ogGit, updateImage

develop
Manuel Aranda Rosales 2025-08-04 09:36:14 +02:00
parent 2b939adc5b
commit 3731697aa7
4 changed files with 80 additions and 0 deletions

View File

@ -101,6 +101,7 @@ resources:
uriTemplate: /git-repositories/deploy-image
controller: App\Controller\DeployGitImageAction
git_update_image:
shortName: Update Git Image
description: Update Git image
@ -110,6 +111,15 @@ resources:
uriTemplate: /git-repositories/update-image
controller: App\Controller\UpdateGitImageAction
get_git_data:
shortName: Get Git Data
description: Get Git data
class: ApiPlatform\Metadata\Post
method: POST
input: App\Dto\Input\GetGitDataInput
uriTemplate: /git-repositories/get-git-data
controller: App\Controller\OgAgent\GetGitDataAction
properties:
App\Entity\GitRepository:
id:

View File

@ -0,0 +1,37 @@
<?php
namespace App\Controller\OgRepository\Git;
use App\Controller\OgRepository\AbstractOgRepositoryController;
use App\Dto\Input\CreateTagInput;
use App\Entity\ImageRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
#[AsController]
class CreateTagAction extends AbstractOgRepositoryController
{
public function __invoke(ImageRepository $repository, CreateTagInput $input): JsonResponse
{
$content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/git/repositories/'.$input->repository.'/tags', [
'json' => [
'commit' => $input->commit,
'message' => $input->message,
'name' => $input->name
]
]);
if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
throw new BadRequestHttpException('Error creating tag');
}
return new JsonResponse(data: [], status: Response::HTTP_OK);
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Dto\Input;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
class CreateTagInput
{
#[Assert\NotNull]
#[Groups(['repository:write'])]
public ?string $repository = null;
#[Assert\NotNull]
#[Groups(['repository:write'])]
public ?string $commit = null;
#[Assert\NotNull]
#[Groups(['repository:write'])]
public ?string $message = null;
#[Assert\NotNull]
#[Groups(['repository:write'])]
public ?string $name = null;
}

View File

@ -23,6 +23,14 @@ class UpdateGitImageInput
#[ApiProperty(description: 'The name of the Git repository to use for this image', example: "mi-repositorio")]
public ?string $gitRepository = null;
#[Groups(['git-repository:write'])]
#[ApiProperty(description: 'The name of the Git branch to use for this image', example: "main")]
public ?string $originalBranch = null;
#[Groups(['git-repository:write'])]
#[ApiProperty(description: 'The name of the Git branch to use for this image', example: "main")]
public ?string $destinationBranch = null;
#[Groups(['git-repository:write'])]
#[ApiProperty(description: 'Whether to queue the update', example: false)]
public bool $queue = false;