few fixes

This commit is contained in:
Andras Bacsai 2023-06-20 15:25:45 +02:00
parent de759290e5
commit f648ab49f7
5 changed files with 29 additions and 26 deletions

View File

@ -43,7 +43,7 @@ class ApplicationDeploymentJob implements ShouldQueue
private string $build_image_name;
private string $production_image_name;
private string $container_name;
private ApplicationPreview|null $preview;
private ApplicationPreview|null $preview = null;
public static int $batch_counter = 0;
public $timeout = 10200;
@ -66,8 +66,10 @@ public function __construct(
$this->application = Application::find($this->application_id);
ray('pullrequestId: ' . $this->pull_request_id);
if ($this->pull_request_id !== 0) {
$this->preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->application->id, $this->pull_request_id);
ray($this->preview);
}
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
@ -319,16 +321,10 @@ private function next(string $status)
}
queue_next_deployment($this->application);
if ($status === ProcessStatus::FINISHED->value) {
Notification::send(
$this->application->environment->project->team,
new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid)
);
$this->application->environment->project->team->notify(new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid, $this->preview));
}
if ($status === ProcessStatus::ERROR->value) {
Notification::send(
$this->application->environment->project->team,
new DeployedWithErrorNotification($this->application, $this->deployment_uuid, $this->preview)
);
$this->application->environment->project->team->notify(new DeployedWithErrorNotification($this->application, $this->deployment_uuid, $this->preview));
}
}
private function execute_in_builder(string $command)

View File

@ -31,7 +31,6 @@ public function __construct(Application $application, string $deployment_uuid, A
$this->application = $application;
$this->deployment_uuid = $deployment_uuid;
$this->preview = $preview;
$this->application_name = data_get($application, 'name');
$this->project_uuid = data_get($application, 'environment.project.uuid');
$this->environment_name = data_get($application, 'environment.name');
@ -55,12 +54,17 @@ public function via(object $notifiable): array
public function toMail(Team $team): MailMessage
{
$mail = new MailMessage();
$mail->subject("✅ New version is deployed of {$this->application_name}");
$pull_request_id = data_get($this->preview, 'pull_request_id', 0);
if ($pull_request_id === 0) {
$mail->subject("✅ New version is deployed of {$this->application_name}");
} else {
$mail->subject("✅ Pull request #{$pull_request_id} of {$this->application_name} deployed successfully");
}
$mail->view('emails.application-deployed-successfully', [
'name' => $this->application_name,
'fqdn' => $this->fqdn,
'url' => $this->deployment_url,
'pull_request_id' => $this->preview->pull_request_id,
'pull_request_id' => $pull_request_id,
]);
return $mail;
}

View File

@ -60,7 +60,7 @@ public function toMail(Team $team): MailMessage
'name' => $this->application_name,
'fqdn' => $this->fqdn,
'url' => $this->deployment_url,
'pull_request_id' => $this->preview->pull_request_id,
'pull_request_id' => data_get($this->preview, 'pull_request_id', 0),
]);
return $mail;
}

View File

@ -1,9 +1,8 @@
Hello,<br><br>
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>
Click the following link to view the deployment logs: <a target="_blank" href="{{ $url }}">View
Deployment</a><br><br>
@if ($pull_request_id === 0)
A new version of <a target="_blank" href="{{ $fqdn }}">{{ $fqdn }}</a> is available.<br><br>
@else
Pull request #{{ $pull_request_id }} is available for review at <a target="_blank"
href="{{ $fqdn }}">{{ $fqdn }}</a><br><br>
@endif
<a target="_blank" href="{{ $url }}">View
Deployment Logs</a><br><br>

View File

@ -1,8 +1,12 @@
Hello,<br><br>
Deployment failed of "{{ $name }}"@if ($pull_request_id !== 0)
:PR#{{ $pull_request_id }}
@endif to <a target="_blank" href="{{ $fqdn }}">{{ $fqdn }}</a><br><br>
Deployment failed of "{{ $name }}"
@if ($pull_request_id !== 0)
: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
Deployment</a><br><br>
Deployment Logs</a><br><br>