feat: formulaire de suggestions créant un ticket Gitea
Les utilisateurs connectés peuvent proposer une modification / un ajout / une correction via un formulaire. La soumission crée automatiquement une issue dans le dépôt Gitea via son API (GiteaIssueService), avec le titre préfixé par le type et l'auteur dans le corps. - config/services.php + .env.example : GITEA_URL/TOKEN/REPO (token secret) - SuggestionController (create/store) + validation - vue suggestions/create + lien dans le header (utilisateurs connectés) - tests: auth requise, création OK, validation, échec API Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class GiteaIssueService
|
||||
{
|
||||
/**
|
||||
* Crée un ticket (issue) dans le dépôt Gitea configuré.
|
||||
*
|
||||
* @return bool true si le ticket a bien été créé, false sinon.
|
||||
*/
|
||||
public function createIssue(string $title, string $body): bool
|
||||
{
|
||||
$url = rtrim((string) config('services.gitea.url'), '/');
|
||||
$repo = trim((string) config('services.gitea.repo'), '/');
|
||||
$token = (string) config('services.gitea.token');
|
||||
|
||||
if ($url === '' || $repo === '' || $token === '') {
|
||||
Log::warning('Gitea non configuré (URL / token / dépôt manquant) : ticket non créé.');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Appel API Gitea impossible : '.$e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($response->failed()) {
|
||||
Log::error('Création du ticket Gitea échouée', [
|
||||
'status' => $response->status(),
|
||||
'body' => $response->body(),
|
||||
]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user