feat : add Gitea repositories list endpoint

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-13 13:58:09 +01:00
parent 5577884c13
commit 7b1aa22c15
2 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\ApiResource\GiteaRepository;
use App\Exception\GiteaApiException;
use App\Service\GiteaApiService;
final readonly class GiteaRepositoryProvider implements ProviderInterface
{
public function __construct(
private GiteaApiService $giteaApiService,
) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
{
try {
$repos = $this->giteaApiService->listRepositories();
} catch (GiteaApiException) {
return [];
}
return array_map(static function (array $repo): GiteaRepository {
$dto = new GiteaRepository();
$dto->fullName = $repo['full_name'] ?? '';
$dto->name = $repo['name'] ?? '';
$dto->owner = $repo['owner']['login'] ?? '';
return $dto;
}, $repos);
}
}