From bb3a1d2f1667ed9032bd1bdbddc6dafed4109328 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 19 Jun 2023 15:34:39 +0200 Subject: [PATCH] wip --- app/Jobs/ApplicationDeploymentJob.php | 10 ++++++++-- .../DeployedSuccessfullyNotification.php | 19 ++++++++++++++----- .../DeployedWithErrorNotification.php | 19 ++++++++++++++----- ...pplication-deployed-successfully.blade.php | 4 +++- .../application-deployed-with-error.blade.php | 5 +++-- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index f45d1d283..215d7e7d9 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -319,10 +319,16 @@ private function next(string $status) } queue_next_deployment($this->application); if ($status === ProcessStatus::ERROR->value) { - Notification::send($this->application->environment->project->team, new DeployedWithErrorNotification($this->application, $this->deployment_uuid)); + Notification::send( + $this->application->environment->project->team, + new DeployedWithErrorNotification($this->application, $this->deployment_uuid, $this->pull_request_id) + ); } if ($status === ProcessStatus::FINISHED->value) { - Notification::send($this->application->environment->project->team, new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid)); + Notification::send( + $this->application->environment->project->team, + new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid, $this->pull_request_id) + ); } } private function execute_in_builder(string $command) diff --git a/app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php b/app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php index 19137df1c..9749b9c2e 100644 --- a/app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php +++ b/app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php @@ -16,18 +16,21 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue { use Queueable; public Application $application; - public string $application_name; public string $deployment_uuid; + public int $pull_request_id; + public string $application_name; public string|null $deployment_url = null; public string $project_uuid; public string $environment_name; public string $fqdn; - public function __construct(Application $application, string $deployment_uuid) + public function __construct(Application $application, string $deployment_uuid, int $pull_request_id = 0) { $this->application = $application; $this->deployment_uuid = $deployment_uuid; + $this->pull_request_id = $pull_request_id; + $this->application_name = data_get($application, 'name'); $this->project_uuid = data_get($application, 'environment.project.uuid'); $this->environment_name = data_get($application, 'environment.name'); @@ -56,14 +59,20 @@ public function toMail(Team $team): MailMessage 'name' => $this->application_name, 'fqdn' => $this->fqdn, 'url' => $this->deployment_url, + 'pull_request_id' => $this->pull_request_id, ]); return $mail; } public function toDiscord(): string { - return '✅ A new version has been deployed of **' . $this->application_name . '**. - -[Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')'; + if ($this->pull_request_id !== 0) { + $message = '✅ Pull request #' . $this->pull_request_id . ' of **' . $this->application_name . '**.'; + } else { + $message = '✅ A new version has been deployed of **' . $this->application_name . '**.'; + } + $message .= "\n\n"; + $message .= '[Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')'; + return $message; } } diff --git a/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php b/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php index 8980d0e46..3ada48475 100644 --- a/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php +++ b/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php @@ -16,18 +16,21 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue { use Queueable; public Application $application; - public string $application_name; public string $deployment_uuid; + public int $pull_request_id; + public string $application_name; public string|null $deployment_url = null; public string $project_uuid; public string $environment_name; public string $fqdn; - public function __construct(Application $application, string $deployment_uuid) + public function __construct(Application $application, string $deployment_uuid, int $pull_request_id = 0) { $this->application = $application; $this->deployment_uuid = $deployment_uuid; + $this->pull_request_id = $pull_request_id; + $this->application_name = data_get($application, 'name'); $this->project_uuid = data_get($application, 'environment.project.uuid'); $this->environment_name = data_get($application, 'environment.name'); @@ -56,14 +59,20 @@ public function toMail(Team $team): MailMessage 'name' => $this->application_name, 'fqdn' => $this->fqdn, 'url' => $this->deployment_url, + 'pull_request_id' => $this->pull_request_id, ]); return $mail; } public function toDiscord(): string { - return '❌ Deployment failed of **' . $this->application_name . '**. - -[Deployment logs](' . $this->deployment_url . ')'; + $message = '❌ Deployment failed of **' . $this->application_name; + if ($this->pull_request_id !== 0) { + $message .= ": PR# {$this->pull_request_id}"; + } + $message .= '**.'; + $message .= "\n\n"; + $message .= "[Deployment logs]({$this->deployment_url})"; + return $message; } } diff --git a/resources/views/emails/application-deployed-successfully.blade.php b/resources/views/emails/application-deployed-successfully.blade.php index ee5a11a10..f0a6a596f 100644 --- a/resources/views/emails/application-deployed-successfully.blade.php +++ b/resources/views/emails/application-deployed-successfully.blade.php @@ -1,6 +1,8 @@ Hello,

-A new version of your application "{{ $name }}" has been deployed to {{ $fqdn }}

Click the following link to view the deployment logs: View diff --git a/resources/views/emails/application-deployed-with-error.blade.php b/resources/views/emails/application-deployed-with-error.blade.php index ed4127cf7..1e499e6e8 100644 --- a/resources/views/emails/application-deployed-with-error.blade.php +++ b/resources/views/emails/application-deployed-with-error.blade.php @@ -1,7 +1,8 @@ Hello,

-Deployment failed of "{{ $name }}" 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