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'); $this->fqdn = data_get($application, 'fqdn'); if (Str::of($this->fqdn)->explode(',')->count() > 1) { $this->fqdn = Str::of($this->fqdn)->explode(',')->first(); } $this->deployment_url = base_url() . "/project/{$this->project_uuid}/{$this->environment_name}/application/{$this->application->uuid}/deployment/{$this->deployment_uuid}"; } public function via(object $notifiable): array { $channels = []; $isEmailEnabled = data_get($notifiable, 'smtp_enabled'); $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); $isSubscribedToEmailEvent = data_get($notifiable, 'smtp_notifications_deployments'); $isSubscribedToDiscordEvent = data_get($notifiable, 'discord_notifications_deployments'); if ($isEmailEnabled && $isSubscribedToEmailEvent) { $channels[] = EmailChannel::class; } if ($isDiscordEnabled && $isSubscribedToDiscordEvent) { $channels[] = DiscordChannel::class; } return $channels; } public function toMail(): MailMessage { $mail = new MailMessage(); $pull_request_id = data_get($this->preview, 'pull_request_id', 0); $fqdn = $this->fqdn; if ($pull_request_id === 0) { $mail->subject("βœ…New version is deployed of {$this->application_name}"); } else { $fqdn = $this->preview->fqdn; $mail->subject("βœ… Pull request #{$pull_request_id} of {$this->application_name} deployed successfully"); } $mail->view('emails.application-deployment-success', [ 'name' => $this->application_name, 'fqdn' => $fqdn, 'deployment_url' => $this->deployment_url, 'pull_request_id' => $pull_request_id, ]); return $mail; } public function toDiscord(): string { if ($this->preview) { $message = 'βœ… New PR' . $this->preview->pull_request_id . ' version successfully deployed of ' . $this->application_name . ' '; if ($this->preview->fqdn) { $message .= '[Open Application](' . $this->preview->fqdn . ') | '; } $message .= '[Deployment logs](' . $this->deployment_url . ')'; } else { $message = 'βœ… New version successfully deployed of ' . $this->application_name . ' '; if ($this->fqdn) { $message .= '[Open Application](' . $this->fqdn . ') | '; } $message .= '[Deployment logs](' . $this->deployment_url . ')'; } return $message; } }