From 5135e28e3ac75282eddd8e027d9ac276156589c9 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Fri, 13 Mar 2026 13:59:32 +0100 Subject: [PATCH] feat : add branch name generation endpoint Co-Authored-By: Claude Opus 4.6 --- src/ApiResource/GiteaBranchName.php | 25 ++++++++++++++++ src/State/GiteaBranchNameProvider.php | 42 +++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/ApiResource/GiteaBranchName.php create mode 100644 src/State/GiteaBranchNameProvider.php diff --git a/src/ApiResource/GiteaBranchName.php b/src/ApiResource/GiteaBranchName.php new file mode 100644 index 0000000..f54913d --- /dev/null +++ b/src/ApiResource/GiteaBranchName.php @@ -0,0 +1,25 @@ + ['gitea_branch_name:read']], + provider: GiteaBranchNameProvider::class, + ), + ], +)] +final class GiteaBranchName +{ + #[Groups(['gitea_branch_name:read'])] + public string $name = ''; +} diff --git a/src/State/GiteaBranchNameProvider.php b/src/State/GiteaBranchNameProvider.php new file mode 100644 index 0000000..42fba49 --- /dev/null +++ b/src/State/GiteaBranchNameProvider.php @@ -0,0 +1,42 @@ +em->getRepository(Task::class)->find($uriVariables['taskId'] ?? 0); + if (null === $task) { + throw new NotFoundHttpException('Task not found.'); + } + + $type = $uriVariables['type'] ?? 'feature'; + if (!in_array($type, self::ALLOWED_TYPES, true)) { + throw new BadRequestHttpException('Invalid branch type.'); + } + + $dto = new GiteaBranchName(); + $dto->name = $this->giteaApiService->generateBranchName($task, $type); + + return $dto; + } +}