feat: slack notifications
This commit is contained in:
@@ -9,7 +9,7 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
use App\Notifications\Dto\SlackMessage;
|
||||
class DeploymentSuccess extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
@@ -44,7 +44,7 @@ class DeploymentSuccess extends Notification implements ShouldQueue
|
||||
if (str($this->fqdn)->explode(',')->count() > 1) {
|
||||
$this->fqdn = str($this->fqdn)->explode(',')->first();
|
||||
}
|
||||
$this->deployment_url = base_url()."/project/{$this->project_uuid}/".urlencode($this->environment_name)."/application/{$this->application->uuid}/deployment/{$this->deployment_uuid}";
|
||||
$this->deployment_url = base_url() . "/project/{$this->project_uuid}/" . urlencode($this->environment_name) . "/application/{$this->application->uuid}/deployment/{$this->deployment_uuid}";
|
||||
}
|
||||
|
||||
public function via(object $notifiable): array
|
||||
@@ -84,21 +84,21 @@ class DeploymentSuccess extends Notification implements ShouldQueue
|
||||
if ($this->preview) {
|
||||
$message = new DiscordMessage(
|
||||
title: ':white_check_mark: Preview deployment successful',
|
||||
description: 'Pull request: '.$this->preview->pull_request_id,
|
||||
description: 'Pull request: ' . $this->preview->pull_request_id,
|
||||
color: DiscordMessage::successColor(),
|
||||
);
|
||||
|
||||
if ($this->preview->fqdn) {
|
||||
$message->addField('Application', '[Link]('.$this->preview->fqdn.')');
|
||||
$message->addField('Application', '[Link](' . $this->preview->fqdn . ')');
|
||||
}
|
||||
|
||||
$message->addField('Project', data_get($this->application, 'environment.project.name'), true);
|
||||
$message->addField('Environment', $this->environment_name, true);
|
||||
$message->addField('Name', $this->application_name, true);
|
||||
$message->addField('Deployment logs', '[Link]('.$this->deployment_url.')');
|
||||
$message->addField('Deployment logs', '[Link](' . $this->deployment_url . ')');
|
||||
} else {
|
||||
if ($this->fqdn) {
|
||||
$description = '[Open application]('.$this->fqdn.')';
|
||||
$description = '[Open application](' . $this->fqdn . ')';
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
@@ -111,7 +111,7 @@ class DeploymentSuccess extends Notification implements ShouldQueue
|
||||
$message->addField('Environment', $this->environment_name, true);
|
||||
$message->addField('Name', $this->application_name, true);
|
||||
|
||||
$message->addField('Deployment logs', '[Link]('.$this->deployment_url.')');
|
||||
$message->addField('Deployment logs', '[Link](' . $this->deployment_url . ')');
|
||||
}
|
||||
|
||||
return $message;
|
||||
@@ -120,7 +120,7 @@ class DeploymentSuccess extends Notification implements ShouldQueue
|
||||
public function toTelegram(): array
|
||||
{
|
||||
if ($this->preview) {
|
||||
$message = 'Coolify: New PR'.$this->preview->pull_request_id.' version successfully deployed of '.$this->application_name.'';
|
||||
$message = 'Coolify: New PR' . $this->preview->pull_request_id . ' version successfully deployed of ' . $this->application_name . '';
|
||||
if ($this->preview->fqdn) {
|
||||
$buttons[] = [
|
||||
'text' => 'Open Application',
|
||||
@@ -128,7 +128,7 @@ class DeploymentSuccess extends Notification implements ShouldQueue
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$message = '✅ New version successfully deployed of '.$this->application_name.'';
|
||||
$message = '✅ New version successfully deployed of ' . $this->application_name . '';
|
||||
if ($this->fqdn) {
|
||||
$buttons[] = [
|
||||
'text' => 'Open Application',
|
||||
@@ -148,4 +148,32 @@ class DeploymentSuccess extends Notification implements ShouldQueue
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user