This commit is contained in:
2025-07-07 21:48:40 +02:00
parent f7de5f8f9c
commit 4a97dad74f
5 changed files with 159 additions and 38 deletions

View File

@ -7,6 +7,8 @@ use App\Entity\Project;
use App\Repository\IssueRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
@ -273,6 +275,31 @@ class RedmineService
return $allIssues;
}
public function getIssue(int $issueId, string $apiKey): array
{
try {
$url = "{$this->baseUrl}/issues/{$issueId}.json?include=allowed_statuses";
$response = $this->client->request('GET', $url, [
'headers' => [
'X-Redmine-API-Key' => $apiKey,
'Accept' => 'application/json',
],
]);
if (200 !== $response->getStatusCode()) {
throw new \RuntimeException('Erreur de communication avec Redmine : '.$response->getStatusCode());
}
$data = $response->toArray();
$data['issue']['sprint'] = $this->getIssueAgile($issueId, $apiKey);
return $data['issue'] ?? [];
} catch (TransportExceptionInterface $e) {
throw new \RuntimeException('Erreur de communication avec Redmine : '.$e->getMessage());
}
}
public function getIssueAgile(int $issueId, string $apiKey): array
{
try {
@ -296,4 +323,64 @@ class RedmineService
throw new \RuntimeException('Erreur de communication avec Redmine : '.$e->getMessage());
}
}
public function updateIssue(int $id, array $data, string $apiKey): array
{
$url = $this->baseUrl.'/issues/'.$id.'.json';
try {
$response = $this->client->request('PUT', $url, [
'headers' => [
'X-Redmine-API-Key' => $apiKey,
'Content-Type' => 'application/json',
],
'json' => ['issue' => $data],
]);
$statusCode = $response->getStatusCode();
$content = trim($response->getContent(false));
// Si vide et code 200, cest peut-être une réussite silencieuse
if ('' === $content) {
return ['success' => true, 'message' => 'OK, mais pas de contenu'];
}
$decoded = json_decode($content, true);
if (isset($decoded['errors']) && is_array($decoded['errors']) && count($decoded['errors']) > 0) {
throw new \RuntimeException('Erreur Redmine : '.implode(', ', $decoded['errors']));
}
return $decoded;
} catch (ClientExceptionInterface|ServerExceptionInterface $e) {
// Erreur HTTP (4xx ou 5xx)
$errorBody = $e->getResponse()->getContent(false);
throw new \RuntimeException('Erreur Redmine: '.$errorBody, $e->getCode(), $e);
} catch (TransportExceptionInterface $e) {
throw new \RuntimeException('Erreur de communication avec Redmine : '.$e->getMessage());
}
}
public function updatePosition(array $data, string $apiKey): array
{
$url = $this->baseUrl.'/agile/board';
try {
$response = $this->client->request('PUT', $url, [
'headers' => [
'X-Redmine-API-Key' => $apiKey,
'Content-Type' => 'application/json',
],
'json' => ['issue' => $data],
]);
return ['ok'];
} catch (ClientExceptionInterface|ServerExceptionInterface $e) {
// Erreur HTTP (4xx ou 5xx)
$errorBody = $e->getResponse()->getContent(false);
throw new \RuntimeException('Erreur Redmine: '.$errorBody, $e->getCode(), $e);
} catch (TransportExceptionInterface $e) {
throw new \RuntimeException('Erreur de communication avec Redmine : '.$e->getMessage());
}
}
}