Merge branch 'next' into fix-environement-route

This commit is contained in:
Andras Bacsai
2024-12-17 12:17:50 +01:00
committed by GitHub
426 changed files with 11051 additions and 5406 deletions

View File

@@ -4,18 +4,14 @@ namespace App\Notifications\Application;
use App\Models\Application;
use App\Models\ApplicationPreview;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Notifications\Dto\PushoverMessage;
use App\Notifications\Dto\SlackMessage;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class DeploymentSuccess extends Notification implements ShouldQueue
class DeploymentSuccess extends CustomEmailNotification
{
use Queueable;
public $tries = 1;
public Application $application;
public ?ApplicationPreview $preview = null;
@@ -53,13 +49,7 @@ class DeploymentSuccess extends Notification implements ShouldQueue
public function via(object $notifiable): array
{
$channels = setNotificationChannels($notifiable, 'deployments');
if (isCloud()) {
// TODO: Make batch notifications work with email
$channels = array_diff($channels, [\App\Notifications\Channels\EmailChannel::class]);
}
return $channels;
return $notifiable->getEnabledChannels('deployment_success');
}
public function toMail(): MailMessage
@@ -152,4 +142,67 @@ class DeploymentSuccess extends Notification implements ShouldQueue
],
];
}
public function toPushover(): PushoverMessage
{
if ($this->preview) {
$title = "Pull request #{$this->preview->pull_request_id} successfully deployed";
$message = 'New PR' . $this->preview->pull_request_id . ' version successfully deployed of ' . $this->application_name . '';
if ($this->preview->fqdn) {
$buttons[] = [
'text' => 'Open Application',
'url' => $this->preview->fqdn,
];
}
} else {
$title = 'New version successfully deployed';
$message = 'New version successfully deployed of ' . $this->application_name . '';
if ($this->fqdn) {
$buttons[] = [
'text' => 'Open Application',
'url' => $this->fqdn,
];
}
}
$buttons[] = [
'text' => 'Deployment logs',
'url' => $this->deployment_url,
];
return new PushoverMessage(
title: $title,
level: 'success',
message: $message,
buttons: [
...$buttons,
],
);
}
public function toSlack(): SlackMessage
{
if ($this->preview) {
$title = "Pull request #{$this->preview->pull_request_id} successfully deployed";
$description = "New version successfully deployed for {$this->application_name}";
if ($this->preview->fqdn) {
$description .= "\nPreview URL: {$this->preview->fqdn}";
}
} else {
$title = 'New version successfully deployed';
$description = "New version successfully deployed for {$this->application_name}";
if ($this->fqdn) {
$description .= "\nApplication URL: {$this->fqdn}";
}
}
$description .= "\n\n**Project:** ".data_get($this->application, 'environment.project.name');
$description .= "\n**Environment:** {$this->environment_name}";
$description .= "\n**Deployment Logs:** {$this->deployment_url}";
return new SlackMessage(
title: $title,
description: $description,
color: SlackMessage::successColor()
);
}
}