This commit is contained in:
Andras Bacsai 2023-06-19 15:43:53 +02:00
parent bb3a1d2f16
commit 8910d5a65d
4 changed files with 33 additions and 25 deletions

View File

@ -318,16 +318,16 @@ private function next(string $status)
dispatch(new InstanceProxyCheckJob());
}
queue_next_deployment($this->application);
if ($status === ProcessStatus::ERROR->value) {
Notification::send(
$this->application->environment->project->team,
new DeployedWithErrorNotification($this->application, $this->deployment_uuid, $this->pull_request_id)
);
}
if ($status === ProcessStatus::FINISHED->value) {
Notification::send(
$this->application->environment->project->team,
new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid, $this->pull_request_id)
new DeployedSuccessfullyNotification($this->application, $this->deployment_uuid)
);
}
if ($status === ProcessStatus::ERROR->value) {
Notification::send(
$this->application->environment->project->team,
new DeployedWithErrorNotification($this->application, $this->deployment_uuid, $this->preview)
);
}
}

View File

@ -3,6 +3,7 @@
namespace App\Notifications\Notifications\Application;
use App\Models\Application;
use App\Models\ApplicationPreview;
use App\Models\Team;
use App\Notifications\Channels\EmailChannel;
use App\Notifications\Channels\DiscordChannel;
@ -17,7 +18,7 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
use Queueable;
public Application $application;
public string $deployment_uuid;
public int $pull_request_id;
public ApplicationPreview|null $preview = null;
public string $application_name;
public string|null $deployment_url = null;
@ -25,11 +26,11 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
public string $environment_name;
public string $fqdn;
public function __construct(Application $application, string $deployment_uuid, int $pull_request_id = 0)
public function __construct(Application $application, string $deployment_uuid, ApplicationPreview|null $preview = null)
{
$this->application = $application;
$this->deployment_uuid = $deployment_uuid;
$this->pull_request_id = $pull_request_id;
$this->preview = $preview;
$this->application_name = data_get($application, 'name');
$this->project_uuid = data_get($application, 'environment.project.uuid');
@ -59,20 +60,20 @@ public function toMail(Team $team): MailMessage
'name' => $this->application_name,
'fqdn' => $this->fqdn,
'url' => $this->deployment_url,
'pull_request_id' => $this->pull_request_id,
'pull_request_id' => $this->preview->pull_request_id,
]);
return $mail;
}
public function toDiscord(): string
{
if ($this->pull_request_id !== 0) {
$message = '✅ Pull request #' . $this->pull_request_id . ' of **' . $this->application_name . '**.';
if ($this->preview) {
$message = '✅ Pull request #' . $this->preview->pull_request_id . ' of **' . $this->application_name . '**. \n\n';
$message .= '[Application Link](' . $this->preview->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')';
} else {
$message = '✅ A new version has been deployed of **' . $this->application_name . '**.';
$message = '✅ A new version has been deployed of **' . $this->application_name . '**. \n\n ';
$message .= '[Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')';
}
$message .= "\n\n";
$message .= '[Application Link](' . $this->fqdn . ') | [Deployment logs](' . $this->deployment_url . ')';
return $message;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Notifications\Notifications\Application;
use App\Models\Application;
use App\Models\ApplicationPreview;
use App\Models\Team;
use App\Notifications\Channels\EmailChannel;
use App\Notifications\Channels\DiscordChannel;
@ -17,7 +18,7 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue
use Queueable;
public Application $application;
public string $deployment_uuid;
public int $pull_request_id;
public ApplicationPreview|null $preview;
public string $application_name;
public string|null $deployment_url = null;
@ -25,11 +26,11 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue
public string $environment_name;
public string $fqdn;
public function __construct(Application $application, string $deployment_uuid, int $pull_request_id = 0)
public function __construct(Application $application, string $deployment_uuid, ApplicationPreview|null $preview)
{
$this->application = $application;
$this->deployment_uuid = $deployment_uuid;
$this->pull_request_id = $pull_request_id;
$this->preview = $preview;
$this->application_name = data_get($application, 'name');
$this->project_uuid = data_get($application, 'environment.project.uuid');
@ -59,7 +60,7 @@ public function toMail(Team $team): MailMessage
'name' => $this->application_name,
'fqdn' => $this->fqdn,
'url' => $this->deployment_url,
'pull_request_id' => $this->pull_request_id,
'pull_request_id' => $this->preview->pull_request_id,
]);
return $mail;
}
@ -67,8 +68,8 @@ public function toMail(Team $team): MailMessage
public function toDiscord(): string
{
$message = '❌ Deployment failed of **' . $this->application_name;
if ($this->pull_request_id !== 0) {
$message .= ": PR# {$this->pull_request_id}";
if ($this->preview) {
$message .= ": PR# {$this->preview->pull_request_id}";
}
$message .= '**.';
$message .= "\n\n";

View File

@ -44,9 +44,15 @@ function getRouteParameters()
function get_latest_version_of_coolify()
{
$response = Http::get('https://cdn.coollabs.io/coolify/versions.json');
$versions = $response->json();
return data_get($versions, 'coolify.v4.version');
try {
$response = Http::get('https://cdn.coollabs.io/coolify/versions.json');
$versions = $response->json();
return data_get($versions, 'coolify.v4.version');
} catch (\Throwable $th) {
//throw $th;
ray($th->getMessage());
return '0.0.0';
}
}
function generate_random_name()