feat: ajout du provisionnement des comptes Gitea pour les utilisateurs lors de la soumission de suggestions
CI - Intégration continue / quality-and-tests (push) Successful in 3m10s
CD - Déploiement continu / deploy (push) Successful in 3m5s

This commit is contained in:
Azmog
2026-07-07 23:43:50 +02:00
parent 507d77246c
commit 85572bd258
9 changed files with 364 additions and 16 deletions
+37 -8
View File
@@ -2,6 +2,7 @@
namespace App\Services;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
@@ -10,9 +11,13 @@ class GiteaIssueService
/**
* Crée un ticket (issue) dans le dépôt Gitea configuré.
*
* Si $sudo est fourni (username Gitea de l'utilisateur), le ticket est
* créé en son nom via l'en-tête "Sudo" (nécessite un token admin). En cas
* de refus, on retombe sur une création avec le compte de service.
*
* @return bool true si le ticket a bien été créé, false sinon.
*/
public function createIssue(string $title, string $body): bool
public function createIssue(string $title, string $body, ?string $sudo = null): bool
{
$url = rtrim((string) config('services.gitea.url'), '/');
$repo = trim((string) config('services.gitea.repo'), '/');
@@ -25,14 +30,15 @@ class GiteaIssueService
}
try {
// Gitea attend l'en-tête "Authorization: token <TOKEN>".
$response = Http::withToken($token, 'token')
->acceptJson()
->timeout(10)
->post("{$url}/api/v1/repos/{$repo}/issues", [
'title' => $title,
'body' => $body,
$response = $this->postIssue($url, $repo, $token, $title, $body, $sudo);
if ($sudo !== null && $response->failed()) {
Log::warning('Création du ticket au nom de l\'utilisateur refusée, repli sur le compte de service.', [
'sudo' => $sudo,
'status' => $response->status(),
]);
$response = $this->postIssue($url, $repo, $token, $title, $body, null);
}
} catch (\Throwable $e) {
Log::error('Appel API Gitea impossible : '.$e->getMessage());
@@ -50,4 +56,27 @@ class GiteaIssueService
return true;
}
private function postIssue(
string $url,
string $repo,
string $token,
string $title,
string $body,
?string $sudo,
): Response {
// Gitea attend l'en-tête "Authorization: token <TOKEN>".
$request = Http::withToken($token, 'token')
->acceptJson()
->timeout(10);
if ($sudo !== null) {
$request = $request->withHeaders(['Sudo' => $sudo]);
}
return $request->post("{$url}/api/v1/repos/{$repo}/issues", [
'title' => $title,
'body' => $body,
]);
}
}