Revert "feat: ajout du provisionnement des comptes Gitea pour les utilisateurs lors de la soumission de suggestions"
This reverts commit 85572bd258.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Http\Client\Response;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -11,13 +10,9 @@ 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, ?string $sudo = null): bool
|
||||
public function createIssue(string $title, string $body): bool
|
||||
{
|
||||
$url = rtrim((string) config('services.gitea.url'), '/');
|
||||
$repo = trim((string) config('services.gitea.repo'), '/');
|
||||
@@ -30,15 +25,14 @@ class GiteaIssueService
|
||||
}
|
||||
|
||||
try {
|
||||
$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(),
|
||||
// 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, null);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Appel API Gitea impossible : '.$e->getMessage());
|
||||
|
||||
@@ -56,27 +50,4 @@ 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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user