diff --git a/app/Http/Livewire/Notifications/DiscordSettings.php b/app/Http/Livewire/Notifications/DiscordSettings.php index 4e47c3ec7..4a9ae4788 100644 --- a/app/Http/Livewire/Notifications/DiscordSettings.php +++ b/app/Http/Livewire/Notifications/DiscordSettings.php @@ -15,16 +15,12 @@ class DiscordSettings extends Component protected $rules = [ 'model.extra_attributes.discord_active' => 'nullable|boolean', 'model.extra_attributes.discord_webhook' => 'required|url', - 'model.extra_attributes.notifications_test' => 'nullable|boolean', - 'model.extra_attributes.notifications_deployments' => 'nullable|boolean', + 'model.extra_attributes.notifications_discord_test' => 'nullable|boolean', + 'model.extra_attributes.notifications_discord_deployments' => 'nullable|boolean', ]; protected $validationAttributes = [ 'model.extra_attributes.discord_webhook' => 'Discord Webhook', ]; - public function instantSaveEvents() - { - $this->saveModel(); - } public function instantSave() { try { @@ -34,7 +30,7 @@ public function instantSave() $this->validate(); } } - private function saveModel() + public function saveModel() { $this->model->save(); if (is_a($this->model, Team::class)) { diff --git a/app/Http/Livewire/Notifications/EmailSettings.php b/app/Http/Livewire/Notifications/EmailSettings.php index 186ca7898..2943ef14f 100644 --- a/app/Http/Livewire/Notifications/EmailSettings.php +++ b/app/Http/Livewire/Notifications/EmailSettings.php @@ -24,8 +24,8 @@ class EmailSettings extends Component 'model.extra_attributes.smtp_password' => 'nullable', 'model.extra_attributes.smtp_timeout' => 'nullable', 'model.extra_attributes.smtp_test_recipients' => 'nullable', - 'model.extra_attributes.notifications_deployments' => 'nullable|boolean', - 'model.extra_attributes.notifications_test' => 'nullable|boolean', + 'model.extra_attributes.notifications_email_test' => 'nullable|boolean', + 'model.extra_attributes.notifications_email_deployments' => 'nullable|boolean', ]; protected $validationAttributes = [ 'model.extra_attributes.smtp_from_address' => 'From Address', @@ -62,7 +62,7 @@ public function submit() $this->model->extra_attributes->smtp_test_recipients = str_replace(' ', '', $this->model->extra_attributes->smtp_test_recipients); $this->saveModel(); } - private function saveModel() + public function saveModel() { $this->model->save(); if (is_a($this->model, Team::class)) { @@ -73,10 +73,7 @@ private function saveModel() public function sendTestNotification() { Notification::send($this->model, new TestNotification); - } - public function instantSaveEvents() - { - $this->saveModel(); + $this->emit('success', 'Test notification sent.'); } public function instantSave() { diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 450e5a8cc..f45d1d283 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -9,7 +9,8 @@ use App\Models\Application; use App\Models\ApplicationDeploymentQueue; use App\Models\ApplicationPreview; -use App\Notifications\Notifications\ApplicationDeployedNotification; +use App\Notifications\Notifications\Application\DeployedSuccessfullyNotification; +use App\Notifications\Notifications\Application\DeployedWithErrorNotification; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -317,7 +318,12 @@ private function next(string $status) dispatch(new InstanceProxyCheckJob()); } queue_next_deployment($this->application); - Notification::send($this->application->environment->project->team, new ApplicationDeployedNotification($this->application, $this->deployment_uuid)); + if ($status === ProcessStatus::ERROR->value) { + Notification::send($this->application->environment->project->team, new DeployedWithErrorNotification($this->application, $this->deployment_uuid)); + } + if ($status === ProcessStatus::FINISHED->value) { + Notification::send($this->application->environment->project->team, new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid)); + } } private function execute_in_builder(string $command) { diff --git a/app/Notifications/Notifications/ApplicationDeployedNotification.php b/app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php similarity index 77% rename from app/Notifications/Notifications/ApplicationDeployedNotification.php rename to app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php index 8718b5a61..19137df1c 100644 --- a/app/Notifications/Notifications/ApplicationDeployedNotification.php +++ b/app/Notifications/Notifications/Application/DeployedSuccessfullyNotification.php @@ -1,6 +1,6 @@ application = $application; - $this->application_name = data_get($application, 'name'); $this->deployment_uuid = $deployment_uuid; + $this->application_name = data_get($application, 'name'); $this->project_uuid = data_get($application, 'environment.project.uuid'); $this->environment_name = data_get($application, 'environment.name'); $this->fqdn = data_get($application, 'fqdn'); @@ -39,10 +40,10 @@ public function __construct(Application $application, string $deployment_uuid) public function via(object $notifiable): array { $channels = []; - if ($notifiable->extra_attributes?->get('email_active') && $notifiable->extra_attributes?->get('notifications_deployments')) { + if ($notifiable->extra_attributes?->get('smtp_active') && $notifiable->extra_attributes?->get('notifications_email_deployments')) { $channels[] = EmailChannel::class; } - if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_deployments')) { + if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_discord_deployments')) { $channels[] = DiscordChannel::class; } return $channels; @@ -50,8 +51,8 @@ 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}"); - $mail->view('emails.application-deployed', [ + $mail->subject("✅ New version is deployed of {$this->application_name}"); + $mail->view('emails.application-deployed-successfully', [ 'name' => $this->application_name, 'fqdn' => $this->fqdn, 'url' => $this->deployment_url, @@ -61,7 +62,8 @@ public function toMail(Team $team): MailMessage public function toDiscord(): string { - return '⚒️ A new version has been deployed of **' . $this->application_name . '**. + return '✅ A new version has been deployed of **' . $this->application_name . '**. + [Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')'; } } diff --git a/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php b/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php new file mode 100644 index 000000000..8980d0e46 --- /dev/null +++ b/app/Notifications/Notifications/Application/DeployedWithErrorNotification.php @@ -0,0 +1,69 @@ +application = $application; + $this->deployment_uuid = $deployment_uuid; + $this->application_name = data_get($application, 'name'); + $this->project_uuid = data_get($application, 'environment.project.uuid'); + $this->environment_name = data_get($application, 'environment.name'); + $this->fqdn = data_get($application, 'fqdn'); + if (Str::of($this->fqdn)->explode(',')->count() > 1) { + $this->fqdn = Str::of($this->fqdn)->explode(',')->first(); + } + $this->deployment_url = base_url() . "/project/{$this->project_uuid}/{$this->environment_name}/application/{$this->application->uuid}/deployment/{$this->deployment_uuid}"; + } + public function via(object $notifiable): array + { + $channels = []; + if ($notifiable->extra_attributes?->get('smtp_active') && $notifiable->extra_attributes?->get('notifications_email_deployments')) { + $channels[] = EmailChannel::class; + } + if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_discord_deployments')) { + $channels[] = DiscordChannel::class; + } + return $channels; + } + public function toMail(Team $team): MailMessage + { + $mail = new MailMessage(); + $mail->subject("❌ Deployment failed of {$this->application_name}"); + $mail->view('emails.application-deployed-with-error', [ + 'name' => $this->application_name, + 'fqdn' => $this->fqdn, + 'url' => $this->deployment_url, + ]); + return $mail; + } + + public function toDiscord(): string + { + return '❌ Deployment failed of **' . $this->application_name . '**. + +[Deployment logs](' . $this->deployment_url . ')'; + } +} diff --git a/app/Notifications/Notifications/TestNotification.php b/app/Notifications/Notifications/TestNotification.php index 9f535e0a3..d98ed1af1 100644 --- a/app/Notifications/Notifications/TestNotification.php +++ b/app/Notifications/Notifications/TestNotification.php @@ -15,10 +15,10 @@ class TestNotification extends Notification implements ShouldQueue public function via(object $notifiable): array { $channels = []; - if ($notifiable->extra_attributes?->get('email_active') && $notifiable->extra_attributes?->get('notifications_test')) { + if ($notifiable->extra_attributes?->get('smtp_active') && $notifiable->extra_attributes?->get('notifications_email_test')) { $channels[] = EmailChannel::class; } - if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_test')) { + if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_discord_test')) { $channels[] = DiscordChannel::class; } return $channels; diff --git a/resources/views/components/notification-subscription.blade.php b/resources/views/components/notification-subscription.blade.php deleted file mode 100644 index 781220867..000000000 --- a/resources/views/components/notification-subscription.blade.php +++ /dev/null @@ -1,9 +0,0 @@ -

Subscribe to events

-
- @if (isDev()) - - @endif - -
diff --git a/resources/views/emails/application-deployed.blade.php b/resources/views/emails/application-deployed-successfully.blade.php similarity index 100% rename from resources/views/emails/application-deployed.blade.php rename to resources/views/emails/application-deployed-successfully.blade.php diff --git a/resources/views/emails/application-deployed-with-error.blade.php b/resources/views/emails/application-deployed-with-error.blade.php new file mode 100644 index 000000000..ed4127cf7 --- /dev/null +++ b/resources/views/emails/application-deployed-with-error.blade.php @@ -0,0 +1,7 @@ +Hello,

+ +Deployment failed of "{{ $name }}" to {{ $fqdn }}

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

diff --git a/resources/views/livewire/notifications/discord-settings.blade.php b/resources/views/livewire/notifications/discord-settings.blade.php index aa66c5ff4..ac943dacb 100644 --- a/resources/views/livewire/notifications/discord-settings.blade.php +++ b/resources/views/livewire/notifications/discord-settings.blade.php @@ -19,5 +19,13 @@ helper="Generate a webhook in Discord.
Example: https://discord.com/api/webhooks/...." required id="model.extra_attributes.discord_webhook" label="Webhook" /> - +

Subscribe to events

+
+ @if (isDev()) + + @endif + +
diff --git a/resources/views/livewire/notifications/email-settings.blade.php b/resources/views/livewire/notifications/email-settings.blade.php index 81c1b78ba..015db8b00 100644 --- a/resources/views/livewire/notifications/email-settings.blade.php +++ b/resources/views/livewire/notifications/email-settings.blade.php @@ -53,5 +53,13 @@ - +

Subscribe to events

+
+ @if (isDev()) + + @endif + +