rector: arrrrr

This commit is contained in:
Andras Bacsai
2025-01-07 14:52:08 +01:00
parent c702ebff6d
commit 16c0cd10d8
349 changed files with 4204 additions and 3712 deletions

View File

@@ -6,11 +6,13 @@ use App\Actions\Docker\GetContainersStatus;
use App\Models\Application;
use App\Models\ApplicationPreview;
use Carbon\Carbon;
use Exception;
use Illuminate\Process\InvokedProcess;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Process;
use Livewire\Component;
use Spatie\Url\Url;
use Throwable;
use Visus\Cuid2\Cuid2;
class Previews extends Component
@@ -41,11 +43,13 @@ class Previews extends Component
['rate_limit_remaining' => $rate_limit_remaining, 'data' => $data] = githubApi(source: $this->application->source, endpoint: "/repos/{$this->application->git_repository}/pulls");
$this->rate_limit_remaining = $rate_limit_remaining;
$this->pull_requests = $data->sortBy('number')->values();
} catch (\Throwable $e) {
} catch (Throwable $e) {
$this->rate_limit_remaining = 0;
return handleError($e, $this);
}
return null;
}
public function save_preview($preview_id)
@@ -65,13 +69,19 @@ class Previews extends Component
}
if (! $preview) {
throw new \Exception('Preview not found');
throw new Exception('Preview not found');
}
$success && $preview->save();
$success && $this->dispatch('success', 'Preview saved.<br><br>Do not forget to redeploy the preview to apply the changes.');
} catch (\Throwable $e) {
if ($success) {
$preview->save();
}
if ($success) {
$this->dispatch('success', 'Preview saved.<br><br>Do not forget to redeploy the preview to apply the changes.');
}
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function generate_preview($preview_id)
@@ -95,8 +105,8 @@ class Previews extends Component
$template = $this->application->preview_url_template;
$host = $url->getHost();
$schema = $url->getScheme();
$random = new Cuid2;
$preview_fqdn = str_replace('{{random}}', $random, $template);
$cuid2 = new Cuid2;
$preview_fqdn = str_replace('{{random}}', $cuid2, $template);
$preview_fqdn = str_replace('{{domain}}', $host, $preview_fqdn);
$preview_fqdn = str_replace('{{pr_id}}', $preview->pull_request_id, $preview_fqdn);
$preview_fqdn = "$schema://$preview_fqdn";
@@ -110,9 +120,9 @@ class Previews extends Component
try {
if ($this->application->build_pack === 'dockercompose') {
$this->setDeploymentUuid();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
$found = ApplicationPreview::query()->where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (! $found && ! is_null($pull_request_html_url)) {
$found = ApplicationPreview::create([
$found = ApplicationPreview::query()->create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
'pull_request_html_url' => $pull_request_html_url,
@@ -123,9 +133,9 @@ class Previews extends Component
$this->application->refresh();
} else {
$this->setDeploymentUuid();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
$found = ApplicationPreview::query()->where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (! $found && ! is_null($pull_request_html_url)) {
$found = ApplicationPreview::create([
$found = ApplicationPreview::query()->create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
'pull_request_html_url' => $pull_request_html_url,
@@ -136,9 +146,11 @@ class Previews extends Component
$this->dispatch('update_links');
$this->dispatch('success', 'Preview added.');
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function add_and_deploy(int $pull_request_id, ?string $pull_request_html_url = null)
@@ -151,9 +163,9 @@ class Previews extends Component
{
try {
$this->setDeploymentUuid();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
$found = ApplicationPreview::query()->where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (! $found && ! is_null($pull_request_html_url)) {
ApplicationPreview::create([
ApplicationPreview::query()->create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
'pull_request_html_url' => $pull_request_html_url,
@@ -173,7 +185,7 @@ class Previews extends Component
'deployment_uuid' => $this->deployment_uuid,
'environment_uuid' => $this->parameters['environment_uuid'],
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
}
@@ -201,9 +213,11 @@ class Previews extends Component
$this->application->refresh();
$this->dispatch('containerStatusUpdated');
$this->dispatch('success', 'Preview Deployment stopped.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function delete(int $pull_request_id)
@@ -219,7 +233,7 @@ class Previews extends Component
$this->stopContainers($containers, $server, $timeout);
}
ApplicationPreview::where('application_id', $this->application->id)
ApplicationPreview::query()->where('application_id', $this->application->id)
->where('pull_request_id', $pull_request_id)
->first()
->delete();
@@ -227,9 +241,11 @@ class Previews extends Component
$this->application->refresh();
$this->dispatch('update_links');
$this->dispatch('success', 'Preview deleted.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
private function stopContainers(array $containers, $server, int $timeout)
@@ -241,7 +257,7 @@ class Previews extends Component
}
$startTime = Carbon::now()->getTimestamp();
while (count($processes) > 0) {
while ($processes !== []) {
$finishedProcesses = array_filter($processes, function ($process) {
return ! $process->running();
});