refactor
This commit is contained in:
92
app/Notifications/Application/DeploymentFailed.php
Normal file
92
app/Notifications/Application/DeploymentFailed.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Application;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationPreview;
|
||||
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 DeploymentFailed extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public Application $application;
|
||||
public string $deployment_uuid;
|
||||
public ApplicationPreview|null $preview;
|
||||
|
||||
public string $application_name;
|
||||
public string|null $deployment_url = null;
|
||||
public string $project_uuid;
|
||||
public string $environment_name;
|
||||
public string|null $fqdn;
|
||||
|
||||
public function __construct(Application $application, string $deployment_uuid, ApplicationPreview|null $preview)
|
||||
{
|
||||
$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');
|
||||
$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 = [];
|
||||
$isEmailEnabled = data_get($notifiable, 'smtp_enabled');
|
||||
$isDiscordEnabled = data_get($notifiable, 'discord_enabled');
|
||||
$isSubscribedToEmailEvent = data_get($notifiable, 'smtp_notifications_deployments');
|
||||
$isSubscribedToDiscordEvent = data_get($notifiable, 'discord_notifications_deployments');
|
||||
|
||||
if ($isEmailEnabled && $isSubscribedToEmailEvent) {
|
||||
$channels[] = EmailChannel::class;
|
||||
}
|
||||
if ($isDiscordEnabled && $isSubscribedToDiscordEvent) {
|
||||
$channels[] = DiscordChannel::class;
|
||||
}
|
||||
return $channels;
|
||||
}
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
$mail = new MailMessage();
|
||||
$pull_request_id = data_get($this->preview, 'pull_request_id', 0);
|
||||
$fqdn = $this->fqdn;
|
||||
if ($pull_request_id === 0) {
|
||||
$mail->subject('❌ Deployment failed of ' . $this->application_name . '.');
|
||||
} else {
|
||||
$fqdn = $this->preview->fqdn;
|
||||
$mail->subject('❌ Pull request #' . $this->preview->pull_request_id . ' of ' . $this->application_name . ' deployment failed.');
|
||||
}
|
||||
|
||||
$mail->view('emails.application-deployment-failed', [
|
||||
'name' => $this->application_name,
|
||||
'fqdn' => $fqdn,
|
||||
'deployment_url' => $this->deployment_url,
|
||||
'pull_request_id' => data_get($this->preview, 'pull_request_id', 0),
|
||||
]);
|
||||
return $mail;
|
||||
}
|
||||
|
||||
public function toDiscord(): string
|
||||
{
|
||||
if ($this->preview) {
|
||||
$message = '❌ Pull request #' . $this->preview->pull_request_id . ' of **' . $this->application_name . '** (' . $this->preview->fqdn . ') deployment failed: ';
|
||||
$message .= '[View Deployment Logs](' . $this->deployment_url . ')';
|
||||
} else {
|
||||
$message = '❌ Deployment failed of **' . $this->application_name . '** (' . $this->fqdn . '): ';
|
||||
$message .= '[View Deployment Logs](' . $this->deployment_url . ')';
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
100
app/Notifications/Application/DeploymentSuccess.php
Normal file
100
app/Notifications/Application/DeploymentSuccess.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Application;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationPreview;
|
||||
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 DeploymentSuccess extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public Application $application;
|
||||
public string $deployment_uuid;
|
||||
public ApplicationPreview|null $preview = null;
|
||||
|
||||
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, ApplicationPreview|null $preview = null)
|
||||
{
|
||||
$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');
|
||||
$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 = [];
|
||||
$isEmailEnabled = data_get($notifiable, 'smtp_enabled');
|
||||
$isDiscordEnabled = data_get($notifiable, 'discord_enabled');
|
||||
$isSubscribedToEmailEvent = data_get($notifiable, 'smtp_notifications_deployments');
|
||||
$isSubscribedToDiscordEvent = data_get($notifiable, 'discord_notifications_deployments');
|
||||
|
||||
if ($isEmailEnabled && $isSubscribedToEmailEvent) {
|
||||
$channels[] = EmailChannel::class;
|
||||
}
|
||||
if ($isDiscordEnabled && $isSubscribedToDiscordEvent) {
|
||||
$channels[] = DiscordChannel::class;
|
||||
}
|
||||
return $channels;
|
||||
}
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
$mail = new MailMessage();
|
||||
$pull_request_id = data_get($this->preview, 'pull_request_id', 0);
|
||||
$fqdn = $this->fqdn;
|
||||
if ($pull_request_id === 0) {
|
||||
$mail->subject("✅New version is deployed of {$this->application_name}");
|
||||
} else {
|
||||
$fqdn = $this->preview->fqdn;
|
||||
$mail->subject("✅ Pull request #{$pull_request_id} of {$this->application_name} deployed successfully");
|
||||
}
|
||||
$mail->view('emails.application-deployment-success', [
|
||||
'name' => $this->application_name,
|
||||
'fqdn' => $fqdn,
|
||||
'deployment_url' => $this->deployment_url,
|
||||
'pull_request_id' => $pull_request_id,
|
||||
]);
|
||||
return $mail;
|
||||
}
|
||||
|
||||
public function toDiscord(): string
|
||||
{
|
||||
if ($this->preview) {
|
||||
$message = '✅ New PR' . $this->preview->pull_request_id . ' version successfully deployed of ' . $this->application_name . '
|
||||
|
||||
';
|
||||
if ($this->preview->fqdn) {
|
||||
$message .= '[Open Application](' . $this->preview->fqdn . ') | ';
|
||||
}
|
||||
$message .= '[Deployment logs](' . $this->deployment_url . ')';
|
||||
} else {
|
||||
$message = '✅ New version successfully deployed of ' . $this->application_name . '
|
||||
|
||||
';
|
||||
if ($this->fqdn) {
|
||||
$message .= '[Open Application](' . $this->fqdn . ') | ';
|
||||
}
|
||||
$message .= '[Deployment logs](' . $this->deployment_url . ')';
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
75
app/Notifications/Application/StatusChanged.php
Normal file
75
app/Notifications/Application/StatusChanged.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Application;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationPreview;
|
||||
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 StatusChanged extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public Application $application;
|
||||
|
||||
public string $application_name;
|
||||
public string|null $application_url = null;
|
||||
public string $project_uuid;
|
||||
public string $environment_name;
|
||||
public string $fqdn;
|
||||
|
||||
public function __construct(Application $application)
|
||||
{
|
||||
$this->application = $application;
|
||||
$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->application_url = base_url() . "/project/{$this->project_uuid}/{$this->environment_name}/application/{$this->application->uuid}";
|
||||
}
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
$channels = [];
|
||||
$isEmailEnabled = data_get($notifiable, 'smtp_enabled');
|
||||
$isDiscordEnabled = data_get($notifiable, 'discord_enabled');
|
||||
$isSubscribedToEmailEvent = data_get($notifiable, 'smtp_notifications_status_changes');
|
||||
$isSubscribedToDiscordEvent = data_get($notifiable, 'discord_notifications_status_changes');
|
||||
|
||||
if ($isEmailEnabled && $isSubscribedToEmailEvent) {
|
||||
$channels[] = EmailChannel::class;
|
||||
}
|
||||
if ($isDiscordEnabled && $isSubscribedToDiscordEvent) {
|
||||
$channels[] = DiscordChannel::class;
|
||||
}
|
||||
return $channels;
|
||||
}
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
$mail = new MailMessage();
|
||||
$fqdn = $this->fqdn;
|
||||
$mail->subject("⛔ {$this->application_name} has been stopped");
|
||||
$mail->view('emails.application-status-changes', [
|
||||
'name' => $this->application_name,
|
||||
'fqdn' => $fqdn,
|
||||
'application_url' => $this->application_url,
|
||||
]);
|
||||
return $mail;
|
||||
}
|
||||
|
||||
public function toDiscord(): string
|
||||
{
|
||||
$message = '⛔ ' . $this->application_name . ' has been stopped.
|
||||
|
||||
';
|
||||
$message .= '[Application URL](' . $this->application_url . ')';
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user