This commit is contained in:
Andras Bacsai 2023-06-19 15:34:39 +02:00
parent 6d2b88c31f
commit bb3a1d2f16
5 changed files with 42 additions and 15 deletions

View File

@ -319,10 +319,16 @@ COPY --from=$this->build_image_name /app/{$this->application->publish_directory}
} }
queue_next_deployment($this->application); queue_next_deployment($this->application);
if ($status === ProcessStatus::ERROR->value) { if ($status === ProcessStatus::ERROR->value) {
Notification::send($this->application->environment->project->team, new DeployedWithErrorNotification($this->application, $this->deployment_uuid)); Notification::send(
$this->application->environment->project->team,
new DeployedWithErrorNotification($this->application, $this->deployment_uuid, $this->pull_request_id)
);
} }
if ($status === ProcessStatus::FINISHED->value) { if ($status === ProcessStatus::FINISHED->value) {
Notification::send($this->application->environment->project->team, new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid)); Notification::send(
$this->application->environment->project->team,
new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid, $this->pull_request_id)
);
} }
} }
private function execute_in_builder(string $command) private function execute_in_builder(string $command)

View File

@ -16,18 +16,21 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
{ {
use Queueable; use Queueable;
public Application $application; public Application $application;
public string $application_name;
public string $deployment_uuid; public string $deployment_uuid;
public int $pull_request_id;
public string $application_name;
public string|null $deployment_url = null; public string|null $deployment_url = null;
public string $project_uuid; public string $project_uuid;
public string $environment_name; public string $environment_name;
public string $fqdn; public string $fqdn;
public function __construct(Application $application, string $deployment_uuid) public function __construct(Application $application, string $deployment_uuid, int $pull_request_id = 0)
{ {
$this->application = $application; $this->application = $application;
$this->deployment_uuid = $deployment_uuid; $this->deployment_uuid = $deployment_uuid;
$this->pull_request_id = $pull_request_id;
$this->application_name = data_get($application, 'name'); $this->application_name = data_get($application, 'name');
$this->project_uuid = data_get($application, 'environment.project.uuid'); $this->project_uuid = data_get($application, 'environment.project.uuid');
$this->environment_name = data_get($application, 'environment.name'); $this->environment_name = data_get($application, 'environment.name');
@ -56,14 +59,20 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
'name' => $this->application_name, 'name' => $this->application_name,
'fqdn' => $this->fqdn, 'fqdn' => $this->fqdn,
'url' => $this->deployment_url, 'url' => $this->deployment_url,
'pull_request_id' => $this->pull_request_id,
]); ]);
return $mail; return $mail;
} }
public function toDiscord(): string public function toDiscord(): string
{ {
return '✅ A new version has been deployed of **' . $this->application_name . '**. if ($this->pull_request_id !== 0) {
$message = '✅ Pull request #' . $this->pull_request_id . ' of **' . $this->application_name . '**.';
[Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')'; } else {
$message = '✅ A new version has been deployed of **' . $this->application_name . '**.';
}
$message .= "\n\n";
$message .= '[Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')';
return $message;
} }
} }

View File

@ -16,18 +16,21 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue
{ {
use Queueable; use Queueable;
public Application $application; public Application $application;
public string $application_name;
public string $deployment_uuid; public string $deployment_uuid;
public int $pull_request_id;
public string $application_name;
public string|null $deployment_url = null; public string|null $deployment_url = null;
public string $project_uuid; public string $project_uuid;
public string $environment_name; public string $environment_name;
public string $fqdn; public string $fqdn;
public function __construct(Application $application, string $deployment_uuid) public function __construct(Application $application, string $deployment_uuid, int $pull_request_id = 0)
{ {
$this->application = $application; $this->application = $application;
$this->deployment_uuid = $deployment_uuid; $this->deployment_uuid = $deployment_uuid;
$this->pull_request_id = $pull_request_id;
$this->application_name = data_get($application, 'name'); $this->application_name = data_get($application, 'name');
$this->project_uuid = data_get($application, 'environment.project.uuid'); $this->project_uuid = data_get($application, 'environment.project.uuid');
$this->environment_name = data_get($application, 'environment.name'); $this->environment_name = data_get($application, 'environment.name');
@ -56,14 +59,20 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue
'name' => $this->application_name, 'name' => $this->application_name,
'fqdn' => $this->fqdn, 'fqdn' => $this->fqdn,
'url' => $this->deployment_url, 'url' => $this->deployment_url,
'pull_request_id' => $this->pull_request_id,
]); ]);
return $mail; return $mail;
} }
public function toDiscord(): string public function toDiscord(): string
{ {
return '❌ Deployment failed of **' . $this->application_name . '**. $message = '❌ Deployment failed of **' . $this->application_name;
if ($this->pull_request_id !== 0) {
[Deployment logs](' . $this->deployment_url . ')'; $message .= ": PR# {$this->pull_request_id}";
}
$message .= '**.';
$message .= "\n\n";
$message .= "[Deployment logs]({$this->deployment_url})";
return $message;
} }
} }

View File

@ -1,6 +1,8 @@
Hello,<br><br> Hello,<br><br>
A new version of your application "{{ $name }}" has been deployed to <a target="_blank" A new version of your application "{{ $name }}"@if ($pull_request_id !== 0)
:PR#{{ $pull_request_id }}
@endif has been deployed to <a target="_blank"
href="{{ $fqdn }}">{{ $fqdn }}</a><br><br> href="{{ $fqdn }}">{{ $fqdn }}</a><br><br>
Click the following link to view the deployment logs: <a target="_blank" href="{{ $url }}">View Click the following link to view the deployment logs: <a target="_blank" href="{{ $url }}">View

View File

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