This commit is contained in:
2025-07-10 22:42:04 +02:00
parent 1cc4db4943
commit ee8220f059
4 changed files with 69 additions and 58 deletions

View File

@ -299,7 +299,7 @@ class RedmineService
public function getIssue(int $issueId, string $apiKey): array
{
try {
$url = "{$this->baseUrl}/issues/{$issueId}.json?include=allowed_statuses";
$url = "{$this->baseUrl}/issues/{$issueId}.json?include=allowed_statuses,journals";
$response = $this->client->request('GET', $url, [
'headers' => [
@ -345,7 +345,7 @@ class RedmineService
}
}
public function updateIssue(int $id, array $data, string $apiKey): array
public function updateIssue(int $id, array $data, ?string $apiKey): array
{
$url = $this->baseUrl.'/issues/'.$id.'.json';
@ -358,25 +358,15 @@ class RedmineService
'json' => ['issue' => $data],
]);
$statusCode = $response->getStatusCode();
$content = trim($response->getContent(false));
if (200 !== $response->getStatusCode()) {
if (401 === $response->getStatusCode()) {
throw new \RuntimeException('Erreur Redmine ('.$response->getStatusCode().') : Opération non autorisée, avez-vous placé votre apikey redmine sur votre profil');
}
// Si vide et code 200, cest peut-être une réussite silencieuse
if ('' === $content) {
return ['success' => true, 'message' => 'OK, mais pas de contenu'];
throw new \RuntimeException('Erreur de communication avec Redmine : '.$response->getStatusCode());
}
$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);
return $response->toArray();
} catch (TransportExceptionInterface $e) {
throw new \RuntimeException('Erreur de communication avec Redmine : '.$e->getMessage());
}