mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
Add notification for deployment completion (#445)
* Add notification for deployment completion Add notification for deployment completion status. * Create `DeploymentCompleted` notification class in `app/Notifications/DeploymentCompleted.php` to handle deployment completion notifications. * Update `app/Actions/Site/Deploy.php` to send `DeploymentCompleted` notification using `Notifier` when a deployment completes or fails. * Import `Notifier` and `DeploymentCompleted` classes in `app/Actions/Site/Deploy.php`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/vitodeploy/vito?shareId=XXXX-XXXX-XXXX-XXXX). * Format with pint * Add tests * Pint format * Delete tests/Feature/Notifications/DeploymentCompletedTest.php * Delete tests/Unit/Notifications/DeploymentCompletedTest.php * 🍻🍻 * tests --------- Co-authored-by: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com> Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
This commit is contained in:
committed by
GitHub
parent
7b723bcba5
commit
d702b95e0c
@ -5,9 +5,11 @@
|
||||
use App\Enums\DeploymentStatus;
|
||||
use App\Exceptions\DeploymentScriptIsEmptyException;
|
||||
use App\Exceptions\SSHError;
|
||||
use App\Facades\Notifier;
|
||||
use App\Models\Deployment;
|
||||
use App\Models\ServerLog;
|
||||
use App\Models\Site;
|
||||
use App\Notifications\DeploymentCompleted;
|
||||
|
||||
class Deploy
|
||||
{
|
||||
@ -53,9 +55,11 @@ public function run(Site $site): Deployment
|
||||
);
|
||||
$deployment->status = DeploymentStatus::FINISHED;
|
||||
$deployment->save();
|
||||
})->catch(function () use ($deployment) {
|
||||
Notifier::send($site, new DeploymentCompleted($deployment, $site));
|
||||
})->catch(function () use ($deployment, $site) {
|
||||
$deployment->status = DeploymentStatus::FAILED;
|
||||
$deployment->save();
|
||||
Notifier::send($site, new DeploymentCompleted($deployment, $site));
|
||||
})->onConnection('ssh');
|
||||
|
||||
return $deployment;
|
||||
|
50
app/Notifications/DeploymentCompleted.php
Normal file
50
app/Notifications/DeploymentCompleted.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Deployment;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class DeploymentCompleted extends AbstractNotification
|
||||
{
|
||||
protected Deployment $deployment;
|
||||
|
||||
protected Site $site;
|
||||
|
||||
public function __construct(Deployment $deployment, Site $site)
|
||||
{
|
||||
$this->deployment = $deployment;
|
||||
$this->site = $site;
|
||||
}
|
||||
|
||||
public function rawText(): string
|
||||
{
|
||||
return __('Deployment for site [:site] has completed with status: :status', [
|
||||
'site' => $this->site->domain,
|
||||
'status' => $this->deployment->status,
|
||||
]);
|
||||
}
|
||||
|
||||
public function toEmail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->subject(__('Deployment Completed'))
|
||||
->line('Deployment for site ['.$this->site->domain.'] has completed with status: '.$this->deployment->status);
|
||||
}
|
||||
|
||||
public function toSlack(object $notifiable): string
|
||||
{
|
||||
return $this->rawText();
|
||||
}
|
||||
|
||||
public function toDiscord(object $notifiable): string
|
||||
{
|
||||
return $this->rawText();
|
||||
}
|
||||
|
||||
public function toTelegram(object $notifiable): string
|
||||
{
|
||||
return $this->rawText();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user