Load Dokploy project details for compose data
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-29 11:00:53 +01:00
parent dba0cd5882
commit 87f348462b
3 changed files with 45 additions and 7 deletions

View File

@@ -33,17 +33,39 @@ class DokployPlatformHealth extends Widget
} }
foreach ($projectMap as $label => $projectId) { foreach ($projectMap as $label => $projectId) {
$project = $client->findProject((string) $projectId); $project = [];
$projectIdString = (string) $projectId;
try {
$project = $client->project($projectIdString);
} catch (\Throwable $exception) {
$project = [];
}
if (empty($project)) {
$project = $client->findProject($projectIdString) ?? [];
$resolvedProjectId = Arr::get($project, 'projectId');
if ($resolvedProjectId) {
try {
$project = $client->project((string) $resolvedProjectId);
} catch (\Throwable $exception) {
$project = $project;
}
}
}
if (! $project) { if (! $project) {
$results[] = [ $results[] = [
'label' => ucfirst((string) $label), 'label' => ucfirst((string) $label),
'project_id' => (string) $projectId, 'project_id' => $projectIdString,
'name' => (string) $projectId, 'name' => $projectIdString,
'status' => 'unreachable', 'status' => 'unreachable',
'error' => "Project {$projectId} not found.", 'error' => "Project {$projectIdString} not found.",
'applications' => [], 'applications' => [],
'services' => [], 'services' => [],
'composes' => [],
'updated_at' => null, 'updated_at' => null,
]; ];
@@ -57,8 +79,8 @@ class DokployPlatformHealth extends Widget
$results[] = [ $results[] = [
'label' => ucfirst((string) $label), 'label' => ucfirst((string) $label),
'project_id' => Arr::get($project, 'projectId', $projectId), 'project_id' => Arr::get($project, 'projectId', $projectIdString),
'name' => Arr::get($project, 'name') ?? Arr::get($project, 'projectName') ?? (string) $projectId, 'name' => Arr::get($project, 'name') ?? Arr::get($project, 'projectName') ?? $projectIdString,
'description' => Arr::get($project, 'description'), 'description' => Arr::get($project, 'description'),
'status' => $this->deriveProjectStatus($applications, $services, $composes), 'status' => $this->deriveProjectStatus($applications, $services, $composes),
'applications' => $applications, 'applications' => $applications,

View File

@@ -49,6 +49,17 @@ class DokployClient
}, 60); }, 60);
} }
public function project(string $projectId): array
{
return $this->cached($this->projectCacheKey($projectId), function () use ($projectId) {
$project = $this->get('/project.one', [
'projectId' => $projectId,
]);
return is_array($project) ? $project : [];
}, 60);
}
public function findProject(string $projectIdOrName): ?array public function findProject(string $projectIdOrName): ?array
{ {
$projects = $this->projects(); $projects = $this->projects();
@@ -357,6 +368,11 @@ class DokployClient
return 'dokploy.projects'; return 'dokploy.projects';
} }
protected function projectCacheKey(string $projectId): string
{
return "dokploy.project.{$projectId}";
}
protected function forgetApplicationCaches(string $applicationId): void protected function forgetApplicationCaches(string $applicationId): void
{ {
Cache::forget($this->applicationCacheKey($applicationId)); Cache::forget($this->applicationCacheKey($applicationId));

View File

@@ -24,7 +24,7 @@ class DokployPlatformHealthWidgetTest extends TestCase
]); ]);
$fakeClient = Mockery::mock(DokployClient::class); $fakeClient = Mockery::mock(DokployClient::class);
$fakeClient->shouldReceive('findProject') $fakeClient->shouldReceive('project')
->with('proj_1') ->with('proj_1')
->andReturn([ ->andReturn([
'projectId' => 'proj_1', 'projectId' => 'proj_1',