From debd2a343320223b485d0ad52d9caa49ccb1d335 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 25 Jul 2024 13:30:38 +0200 Subject: [PATCH] fix: link in task failed job notifications --- app/Models/Application.php | 16 ++++++++++++++-- app/Models/Service.php | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/Models/Application.php b/app/Models/Application.php index 7b39292e0..63fae03b6 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -232,12 +232,24 @@ class Application extends BaseModel public function failedTaskLink($task_uuid) { if (data_get($this, 'environment.project.uuid')) { - return route('project.application.scheduled-tasks', [ + $route = route('project.application.scheduled-tasks', [ 'project_uuid' => data_get($this, 'environment.project.uuid'), 'environment_name' => data_get($this, 'environment.name'), 'application_uuid' => data_get($this, 'uuid'), 'task_uuid' => $task_uuid, ]); + $settings = InstanceSettings::get(); + if (data_get($settings, 'fqdn')) { + $url = Url::fromString($route); + $url = $url->withPort(null); + $fqdn = data_get($settings, 'fqdn'); + $fqdn = str_replace(['http://', 'https://'], '', $fqdn); + $url = $url->withHost($fqdn); + + return $url->__toString(); + } + + return $route; } return null; @@ -1270,7 +1282,7 @@ class Application extends BaseModel $template = $this->preview_url_template; $host = $url->getHost(); $schema = $url->getScheme(); - $random = new Cuid2(7); + $random = new Cuid2(); $preview_fqdn = str_replace('{{random}}', $random, $template); $preview_fqdn = str_replace('{{domain}}', $host, $preview_fqdn); $preview_fqdn = str_replace('{{pr_id}}', $pull_request_id, $preview_fqdn); diff --git a/app/Models/Service.php b/app/Models/Service.php index 8336b90c8..d153d2841 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection; use OpenApi\Attributes as OA; +use Spatie\Url\Url; use Symfony\Component\Yaml\Yaml; #[OA\Schema( @@ -764,12 +765,24 @@ class Service extends BaseModel public function failedTaskLink($task_uuid) { if (data_get($this, 'environment.project.uuid')) { - return route('project.service.scheduled-tasks', [ + $route = route('project.service.scheduled-tasks', [ 'project_uuid' => data_get($this, 'environment.project.uuid'), 'environment_name' => data_get($this, 'environment.name'), 'service_uuid' => data_get($this, 'uuid'), 'task_uuid' => $task_uuid, ]); + $settings = InstanceSettings::get(); + if (data_get($settings, 'fqdn')) { + $url = Url::fromString($route); + $url = $url->withPort(null); + $fqdn = data_get($settings, 'fqdn'); + $fqdn = str_replace(['http://', 'https://'], '', $fqdn); + $url = $url->withHost($fqdn); + + return $url->__toString(); + } + + return $route; } return null;