From c39a287b47a7a8aeeba4ae5e533638f5a4cde2b8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Fri, 13 Mar 2026 17:02:05 +0100 Subject: [PATCH] feat(compose-preview): populate fqdn from docker_compose_domains The generate_preview_fqdn_compose method now extracts and populates the fqdn field from docker_compose_domains, making it available for webhook notifications. This handles multiple domains across services and gracefully sets fqdn to null when no domains are configured. --- app/Models/ApplicationPreview.php | 10 +++ tests/Feature/ComposePreviewFqdnTest.php | 77 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 tests/Feature/ComposePreviewFqdnTest.php diff --git a/app/Models/ApplicationPreview.php b/app/Models/ApplicationPreview.php index 7373fdb16..3b7bf3030 100644 --- a/app/Models/ApplicationPreview.php +++ b/app/Models/ApplicationPreview.php @@ -166,6 +166,16 @@ public function generate_preview_fqdn_compose() } $this->docker_compose_domains = json_encode($docker_compose_domains); + + // Populate fqdn from generated domains so webhook notifications can read it + $allDomains = collect($docker_compose_domains) + ->pluck('domain') + ->filter(fn ($d) => ! empty($d)) + ->flatMap(fn ($d) => explode(',', $d)) + ->implode(','); + + $this->fqdn = ! empty($allDomains) ? $allDomains : null; + $this->save(); } } diff --git a/tests/Feature/ComposePreviewFqdnTest.php b/tests/Feature/ComposePreviewFqdnTest.php new file mode 100644 index 000000000..c62f905d6 --- /dev/null +++ b/tests/Feature/ComposePreviewFqdnTest.php @@ -0,0 +1,77 @@ +create([ + 'build_pack' => 'dockercompose', + 'docker_compose_domains' => json_encode([ + 'web' => ['domain' => 'https://example.com'], + ]), + ]); + + $preview = ApplicationPreview::create([ + 'application_id' => $application->id, + 'pull_request_id' => 42, + 'docker_compose_domains' => $application->docker_compose_domains, + ]); + + $preview->generate_preview_fqdn_compose(); + + $preview->refresh(); + + expect($preview->fqdn)->not->toBeNull(); + expect($preview->fqdn)->toContain('42'); + expect($preview->fqdn)->toContain('example.com'); +}); + +it('populates fqdn with multiple domains from multiple services', function () { + $application = Application::factory()->create([ + 'build_pack' => 'dockercompose', + 'docker_compose_domains' => json_encode([ + 'web' => ['domain' => 'https://web.example.com'], + 'api' => ['domain' => 'https://api.example.com'], + ]), + ]); + + $preview = ApplicationPreview::create([ + 'application_id' => $application->id, + 'pull_request_id' => 7, + 'docker_compose_domains' => $application->docker_compose_domains, + ]); + + $preview->generate_preview_fqdn_compose(); + + $preview->refresh(); + + expect($preview->fqdn)->not->toBeNull(); + $domains = explode(',', $preview->fqdn); + expect($domains)->toHaveCount(2); + expect($preview->fqdn)->toContain('web.example.com'); + expect($preview->fqdn)->toContain('api.example.com'); +}); + +it('sets fqdn to null when no domains are configured', function () { + $application = Application::factory()->create([ + 'build_pack' => 'dockercompose', + 'docker_compose_domains' => json_encode([ + 'web' => ['domain' => ''], + ]), + ]); + + $preview = ApplicationPreview::create([ + 'application_id' => $application->id, + 'pull_request_id' => 99, + 'docker_compose_domains' => $application->docker_compose_domains, + ]); + + $preview->generate_preview_fqdn_compose(); + + $preview->refresh(); + + expect($preview->fqdn)->toBeNull(); +});