-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Co-authored-by: Saeed Vaziry <[email protected]>
- Loading branch information
1 parent
7b723bc
commit d702b95
Showing
4 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
namespace Tests; | ||
|
||
use App\Enums\Database; | ||
use App\Enums\NotificationChannel; | ||
use App\Enums\ServiceStatus; | ||
use App\Enums\UserRole; | ||
use App\Enums\Webserver; | ||
use App\Models\NotificationChannel; | ||
use App\Models\Server; | ||
use App\Models\Site; | ||
use App\Models\SourceControl; | ||
|
@@ -24,6 +24,8 @@ abstract class TestCase extends BaseTestCase | |
|
||
protected Site $site; | ||
|
||
protected NotificationChannel $notificationChannel; | ||
|
||
public const EXPECT_SUCCESS = true; | ||
|
||
public const EXPECT_FAILURE = false; | ||
|
@@ -40,8 +42,8 @@ protected function setUp(): void | |
]); | ||
$this->user->createDefaultProject(); | ||
|
||
\App\Models\NotificationChannel::factory()->create([ | ||
'provider' => NotificationChannel::EMAIL, | ||
$this->notificationChannel = NotificationChannel::factory()->create([ | ||
'provider' => \App\Enums\NotificationChannel::EMAIL, | ||
'connected' => true, | ||
'data' => [ | ||
'email' => '[email protected]', | ||
|