Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions src/Controller/Admin/DetectionResultCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
10 changes: 0 additions & 10 deletions src/Entity/DetectionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions templates/EasyAdminBundle/Fields/harvester_messages.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}
<span class="text-muted">None</span>
{% else %}
<ul class="list-unstyled mb-0">
{% for item in field.value %}
<li class="mb-3">
<div>
<strong>{{ item.source }}</strong>
{%- if item.container is defined %} in {{ item.container }}{% endif %}
{%- if item.exitCode is defined %} (exit {{ item.exitCode }}){% endif %}
</div>
{% if item.command is defined %}
<code>{{ item.command }}</code>
{% endif %}
<pre class="mb-0" style="white-space: pre-wrap; overflow-wrap: anywhere">{{ item.message }}</pre>
</li>
{% endfor %}
</ul>
{% endif %}
27 changes: 27 additions & 0 deletions tests/Controller/Admin/AdminSmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Loading