diff --git a/CHANGELOG.md b/CHANGELOG.md index e9c7c06..ca49197 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [#174](https://github.com/itk-dev/devops_itksites/pull/174) + Show detection result errors and warnings as readable messages instead of + JSON, so long messages are no longer cut off + ## [1.20.0] - 2026-11-04 - [#172](https://github.com/itk-dev/devops_itksites/pull/172) diff --git a/src/Controller/Admin/DetectionResultCrudController.php b/src/Controller/Admin/DetectionResultCrudController.php index ba57bd0..dc085e8 100644 --- a/src/Controller/Admin/DetectionResultCrudController.php +++ b/src/Controller/Admin/DetectionResultCrudController.php @@ -55,12 +55,10 @@ public function configureFields(string $pageName): iterable yield DateTimeField::new('modifiedAt')->hideOnIndex(); yield DateTimeField::new('lastContact'); yield TextMonospaceField::new('harvesterVersion'); - yield Field::new('prettyErrors')->onlyOnDetail()->setLabel('Errors') - ->setTemplatePath('EasyAdminBundle/Fields/code_highlight.html.twig') - ->setCustomOption('language', 'json'); - yield Field::new('prettyWarnings')->onlyOnDetail()->setLabel('Warnings') - ->setTemplatePath('EasyAdminBundle/Fields/code_highlight.html.twig') - ->setCustomOption('language', 'json'); + yield Field::new('errors')->onlyOnDetail() + ->setTemplatePath('EasyAdminBundle/Fields/harvester_messages.html.twig'); + yield Field::new('warnings')->onlyOnDetail() + ->setTemplatePath('EasyAdminBundle/Fields/harvester_messages.html.twig'); yield Field::new('prettyData')->onlyOnDetail()->setLabel('Data') ->setTemplatePath('EasyAdminBundle/Fields/code_highlight.html.twig') ->setCustomOption('language', 'json'); diff --git a/src/Entity/DetectionResult.php b/src/Entity/DetectionResult.php index c9b5003..cae5cc5 100644 --- a/src/Entity/DetectionResult.php +++ b/src/Entity/DetectionResult.php @@ -219,16 +219,6 @@ public function setWarnings(array $warnings): self return $this; } - public function getPrettyErrors(): string - { - return json_encode($this->errors, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR); - } - - public function getPrettyWarnings(): string - { - return json_encode($this->warnings, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR); - } - public function getHash(): ?string { return $this->hash; diff --git a/templates/EasyAdminBundle/Fields/harvester_messages.html.twig b/templates/EasyAdminBundle/Fields/harvester_messages.html.twig new file mode 100644 index 0000000..eb24295 --- /dev/null +++ b/templates/EasyAdminBundle/Fields/harvester_messages.html.twig @@ -0,0 +1,22 @@ +{# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #} +{# Errors or warnings from the harvester: a list of {source, message} with + optional container, command and exitCode. #} +{% if field.value is empty %} + None +{% else %} + +{% endif %} diff --git a/tests/Controller/Admin/AdminSmokeTest.php b/tests/Controller/Admin/AdminSmokeTest.php index 0476086..45051fe 100644 --- a/tests/Controller/Admin/AdminSmokeTest.php +++ b/tests/Controller/Admin/AdminSmokeTest.php @@ -21,6 +21,7 @@ use App\Controller\Admin\ServiceCertificateCrudController; use App\Controller\Admin\SiteCrudController; use App\Entity\Advisory; +use App\Entity\DetectionResult; use App\Entity\Installation; use App\Entity\Module; use App\Entity\ModuleVersion; @@ -193,6 +194,32 @@ public static function packageCrudControllerProvider(): iterable yield 'PackageVersion' => [PackageVersionCrudController::class, 3, 1]; } + public function testDetectionResultDetailShowsErrorMessageInFull(): void + { + $client = static::createClient(); + $entityManager = static::getContainer()->get('doctrine')->getManager(); + $client->loginUser($entityManager->getRepository(User::class)->findOneBy([])); + + $result = $entityManager->getRepository(DetectionResult::class)->findOneBy([]); + $message = "In CooldownPolicyConfig.php line 117:\n bower-asset/jquery 4.0.0 has no published-time"; + $result->setErrors([['source' => 'composer', 'message' => $message, 'container' => 'phpfpm', 'command' => 'composer outdated --all --format=json', 'exitCode' => 1]]); + $entityManager->flush(); + + $url = static::getContainer()->get(AdminUrlGenerator::class) + ->setController(DetectionResultCrudController::class) + ->setAction(Crud::PAGE_DETAIL) + ->setEntityId($result->getId()) + ->generateUrl(); + + $client->request('GET', $url); + + $this->assertResponseIsSuccessful(); + // The message keeps its line breaks instead of showing a JSON-escaped "\n". + $this->assertSelectorTextContains('pre', 'has no published-time'); + $this->assertStringContainsString($message, $client->getCrawler()->filter('pre')->text(null, false)); + $this->assertSelectorTextContains('li code', 'composer outdated --all --format=json'); + } + public function testDockerImagesFilterByRegistry(): void { $client = static::createClient();