This commit is contained in:
Andras Bacsai
2023-06-19 15:24:04 +02:00
parent f7dd110a49
commit 6d2b88c31f
11 changed files with 121 additions and 37 deletions

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Notifications\Notifications;
namespace App\Notifications\Notifications\Application;
use App\Models\Application;
use App\Models\Team;
@@ -12,12 +12,13 @@ use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;
class ApplicationDeployedNotification extends Notification implements ShouldQueue
class DeployedSuccessfullyNotification extends Notification implements ShouldQueue
{
use Queueable;
public Application $application;
public string $application_name;
public string $deployment_uuid;
public string|null $deployment_url = null;
public string $project_uuid;
public string $environment_name;
@@ -26,8 +27,8 @@ class ApplicationDeployedNotification extends Notification implements ShouldQueu
public function __construct(Application $application, string $deployment_uuid)
{
$this->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 @@ class ApplicationDeployedNotification extends Notification implements ShouldQueu
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 @@ class ApplicationDeployedNotification extends Notification implements ShouldQueu
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 @@ class ApplicationDeployedNotification extends Notification implements ShouldQueu
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 . ')';
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Notifications\Notifications\Application;
use App\Models\Application;
use App\Models\Team;
use App\Notifications\Channels\EmailChannel;
use App\Notifications\Channels\DiscordChannel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;
class DeployedWithErrorNotification extends Notification implements ShouldQueue
{
use Queueable;
public Application $application;
public string $application_name;
public string $deployment_uuid;
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)
{
$this->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 . ')';
}
}

View File

@@ -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;