This commit is contained in:
Andras Bacsai 2023-06-21 10:48:43 +02:00
parent cfc2405596
commit d0af38fb14
6 changed files with 41 additions and 32 deletions

View File

@ -29,7 +29,8 @@ class SendMessageToDiscordJob implements ShouldQueue
public function __construct( public function __construct(
public string $text, public string $text,
public string $webhookUrl public string $webhookUrl
) {} ) {
}
/** /**
* Execute the job. * Execute the job.
@ -39,7 +40,7 @@ class SendMessageToDiscordJob implements ShouldQueue
$payload = [ $payload = [
'content' => $this->text, 'content' => $this->text,
]; ];
ray($payload);
Http::post($this->webhookUrl, $payload); Http::post($this->webhookUrl, $payload);
} }
} }

View File

@ -56,19 +56,21 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
} }
return $channels; return $channels;
} }
public function toMail(Team $team): MailMessage public function toMail(): MailMessage
{ {
$mail = new MailMessage(); $mail = new MailMessage();
$pull_request_id = data_get($this->preview, 'pull_request_id', 0); $pull_request_id = data_get($this->preview, 'pull_request_id', 0);
$fqdn = $this->fqdn;
if ($pull_request_id === 0) { if ($pull_request_id === 0) {
$mail->subject("✅ New version is deployed of {$this->application_name}"); $mail->subject("✅ New version is deployed of {$this->application_name}");
} else { } else {
$fqdn = $this->preview->fqdn;
$mail->subject("✅ Pull request #{$pull_request_id} of {$this->application_name} deployed successfully"); $mail->subject("✅ Pull request #{$pull_request_id} of {$this->application_name} deployed successfully");
} }
$mail->view('emails.application-deployed-successfully', [ $mail->view('emails.application-deployed-successfully', [
'name' => $this->application_name, 'name' => $this->application_name,
'fqdn' => $this->fqdn, 'fqdn' => $fqdn,
'url' => $this->deployment_url, 'deployment_url' => $this->deployment_url,
'pull_request_id' => $pull_request_id, 'pull_request_id' => $pull_request_id,
]); ]);
return $mail; return $mail;
@ -77,10 +79,11 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
public function toDiscord(): string public function toDiscord(): string
{ {
if ($this->preview) { if ($this->preview) {
$message = '✅ Pull request #' . $this->preview->pull_request_id . ' of **' . $this->application_name . '**. \n\n'; $message = '✅ Pull request #' . $this->preview->pull_request_id . ' of **' . $this->application_name . '** deployed successfully: ';
$message .= '[Application Link](' . $this->preview->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')'; $message .= '[Application Link](' . $this->preview->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')';
} else { } else {
$message = '✅ A new version has been deployed of **' . $this->application_name . '**. \n\n '; $message = '✅ A new version has been deployed of **' . $this->application_name . '**.';
$message .= "\n\n";
$message .= '[Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')'; $message .= '[Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')';
} }
return $message; return $message;

View File

@ -57,14 +57,22 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue
} }
return $channels; return $channels;
} }
public function toMail(Team $team): MailMessage public function toMail(): MailMessage
{ {
$mail = new MailMessage(); $mail = new MailMessage();
$mail->subject("❌ Deployment failed of {$this->application_name}"); $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-deployed-with-error', [ $mail->view('emails.application-deployed-with-error', [
'name' => $this->application_name, 'name' => $this->application_name,
'fqdn' => $this->fqdn, 'fqdn' => $fqdn,
'url' => $this->deployment_url, 'deployment_url' => $this->deployment_url,
'pull_request_id' => data_get($this->preview, 'pull_request_id', 0), 'pull_request_id' => data_get($this->preview, 'pull_request_id', 0),
]); ]);
return $mail; return $mail;
@ -72,13 +80,13 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue
public function toDiscord(): string public function toDiscord(): string
{ {
$message = '❌ Deployment failed of **' . $this->application_name;
if ($this->preview) { if ($this->preview) {
$message .= ": PR# {$this->preview->pull_request_id}"; $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 . ')';
} }
$message .= '**.';
$message .= "\n\n";
$message .= "[Deployment logs]({$this->deployment_url})";
return $message; return $message;
} }
} }

View File

@ -45,8 +45,9 @@ class TestNotification extends Notification implements ShouldQueue
public function toDiscord(): string public function toDiscord(): string
{ {
return 'This is a test Discord notification from Coolify. $message = 'This is a test Discord notification from Coolify.';
$message .= "\n\n";
[Go to your dashboard](' . base_url() . ')'; $message .= '[Go to your dashboard](' . base_url() . ')';
return $message;
} }
} }

View File

@ -1,8 +1,8 @@
@if ($pull_request_id === 0) @if ($pull_request_id === 0)
A new version of <a target="_blank" href="{{ $fqdn }}">{{ $fqdn }}</a> is available.<br><br> A new version of <a target="_blank" href="{{ $fqdn }}">{{ $fqdn }}</a> is available:
@else @else
Pull request #{{ $pull_request_id }} is available for review at <a target="_blank" Pull request #{{ $pull_request_id }} of {{ $name }} deployed successfully: <a target="_blank"
href="{{ $fqdn }}">{{ $fqdn }}</a><br><br> href="{{ $fqdn }}">Application Link</a> |
@endif @endif
<a target="_blank" href="{{ $url }}">View <a target="_blank" href="{{ $deployment_url }}">View
Deployment Logs</a><br><br> Deployment Logs</a><br><br>

View File

@ -1,12 +1,8 @@
Hello,<br><br>
Deployment failed of "{{ $name }}"
@if ($pull_request_id !== 0) @if ($pull_request_id !== 0)
:PR #{{ $pull_request_id }} Pull Request #{{ $pull_request_id }} of {{ $name }} (<a target="_blank"
href="{{ $fqdn }}">{{ $fqdn }}</a>) deployment failed:
@else
Deployment failed of {{ $name }} (<a target="_blank" href="{{ $fqdn }}">{{ $fqdn }}</a>):
@endif @endif
to <a target="_blank" href="{{ $fqdn }}">{{ $fqdn }}</a>.<br><br> <a target="_blank" href="{{ $deployment_url }}">View Deployment Logs</a><br><br>
Click the following link to view the deployment logs: <a target="_blank" href="{{ $url }}">View
Deployment Logs</a><br><br>