From f648ab49f7288fad0b6483586795a05d9cf1d0c7 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 20 Jun 2023 15:25:45 +0200 Subject: [PATCH] few fixes --- app/Jobs/ApplicationDeploymentJob.php | 14 +++++--------- .../DeployedSuccessfullyNotification.php | 10 +++++++--- .../DeployedWithErrorNotification.php | 2 +- .../application-deployed-successfully.blade.php | 17 ++++++++--------- .../application-deployed-with-error.blade.php | 12 ++++++++---- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 37258845a..4f3911353 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -43,7 +43,7 @@ class ApplicationDeploymentJob implements ShouldQueue private string $build_image_name; private string $production_image_name; private string $container_name; - private ApplicationPreview|null $preview; + private ApplicationPreview|null $preview = null; public static int $batch_counter = 0; public $timeout = 10200; @@ -66,8 +66,10 @@ public function __construct( $this->application = Application::find($this->application_id); + ray('pullrequestId: ' . $this->pull_request_id); if ($this->pull_request_id !== 0) { $this->preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->application->id, $this->pull_request_id); + ray($this->preview); } $this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first(); @@ -319,16 +321,10 @@ private function next(string $status) } queue_next_deployment($this->application); if ($status === ProcessStatus::FINISHED->value) { - Notification::send( - $this->application->environment->project->team, - new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid) - ); + $this->application->environment->project->team->notify(new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid, $this->preview)); } if ($status === ProcessStatus::ERROR->value) { - Notification::send( - $this->application->environment->project->team, - new DeployedWithErrorNotification($this->application, $this->deployment_uuid, $this->preview) - ); + $this->application->environment->project->team->notify(new DeployedWithErrorNotification($this->application, $this->deployment_uuid, $this->preview)); } } private function execute_in_builder(string $command) diff --git a/app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php b/app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php index c8ed0293d..a13ad7901 100644 --- a/app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php +++ b/app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php @@ -31,7 +31,6 @@ public function __construct(Application $application, string $deployment_uuid, A $this->application = $application; $this->deployment_uuid = $deployment_uuid; $this->preview = $preview; - $this->application_name = data_get($application, 'name'); $this->project_uuid = data_get($application, 'environment.project.uuid'); $this->environment_name = data_get($application, 'environment.name'); @@ -55,12 +54,17 @@ public function via(object $notifiable): array public function toMail(Team $team): MailMessage { $mail = new MailMessage(); - $mail->subject("✅ New version is deployed of {$this->application_name}"); + $pull_request_id = data_get($this->preview, 'pull_request_id', 0); + if ($pull_request_id === 0) { + $mail->subject("✅ New version is deployed of {$this->application_name}"); + } else { + $mail->subject("✅ Pull request #{$pull_request_id} of {$this->application_name} deployed successfully"); + } $mail->view('emails.application-deployed-successfully', [ 'name' => $this->application_name, 'fqdn' => $this->fqdn, 'url' => $this->deployment_url, - 'pull_request_id' => $this->preview->pull_request_id, + 'pull_request_id' => $pull_request_id, ]); return $mail; } diff --git a/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php b/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php index 0499cc161..ecbc97359 100644 --- a/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php +++ b/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php @@ -60,7 +60,7 @@ public function toMail(Team $team): MailMessage 'name' => $this->application_name, 'fqdn' => $this->fqdn, 'url' => $this->deployment_url, - 'pull_request_id' => $this->preview->pull_request_id, + 'pull_request_id' => data_get($this->preview, 'pull_request_id', 0), ]); return $mail; } diff --git a/resources/views/emails/application-deployed-successfully.blade.php b/resources/views/emails/application-deployed-successfully.blade.php index f0a6a596f..0e4fccf8e 100644 --- a/resources/views/emails/application-deployed-successfully.blade.php +++ b/resources/views/emails/application-deployed-successfully.blade.php @@ -1,9 +1,8 @@ -Hello,

- -A new version of your application "{{ $name }}"@if ($pull_request_id !== 0) - :PR#{{ $pull_request_id }} -@endif has been deployed to {{ $fqdn }}

- -Click the following link to view the deployment logs: View - Deployment

+@if ($pull_request_id === 0) + A new version of {{ $fqdn }} is available.

+@else + Pull request #{{ $pull_request_id }} is available for review at {{ $fqdn }}

+@endif +View + Deployment Logs

diff --git a/resources/views/emails/application-deployed-with-error.blade.php b/resources/views/emails/application-deployed-with-error.blade.php index 1e499e6e8..d01c96bf8 100644 --- a/resources/views/emails/application-deployed-with-error.blade.php +++ b/resources/views/emails/application-deployed-with-error.blade.php @@ -1,8 +1,12 @@ Hello,

-Deployment failed of "{{ $name }}"@if ($pull_request_id !== 0) - :PR#{{ $pull_request_id }} -@endif to {{ $fqdn }}

+Deployment failed of "{{ $name }}" + +@if ($pull_request_id !== 0) + :PR #{{ $pull_request_id }} +@endif + +to {{ $fqdn }}.

Click the following link to view the deployment logs: View - Deployment

+ Deployment Logs