fix: handle / in preselecting branches

This commit is contained in:
Andras Bacsai 2024-07-18 12:03:48 +02:00
parent 997a262b6c
commit 4c031a7c05
2 changed files with 31 additions and 33 deletions

View File

@ -25,11 +25,11 @@ class PublicGitRepository extends Component
public $query;
public bool $branch_found = false;
public bool $branchFound = false;
public string $selected_branch = 'main';
public string $selectedBranch = 'main';
public bool $is_static = false;
public bool $isStatic = false;
public ?string $publish_directory = null;
@ -62,7 +62,7 @@ class PublicGitRepository extends Component
protected $rules = [
'repository_url' => 'required|url',
'port' => 'required|numeric',
'is_static' => 'required|boolean',
'isStatic' => 'required|boolean',
'publish_directory' => 'nullable|string',
'build_pack' => 'required|string',
'base_directory' => 'nullable|string',
@ -72,7 +72,7 @@ class PublicGitRepository extends Component
protected $validationAttributes = [
'repository_url' => 'repository',
'port' => 'port',
'is_static' => 'static',
'isStatic' => 'static',
'publish_directory' => 'publish directory',
'build_pack' => 'build pack',
'base_directory' => 'base directory',
@ -106,17 +106,17 @@ public function updatedBuildPack()
$this->port = 3000;
} elseif ($this->build_pack === 'static') {
$this->show_is_static = false;
$this->is_static = false;
$this->isStatic = false;
$this->port = 80;
} else {
$this->show_is_static = false;
$this->is_static = false;
$this->isStatic = false;
}
}
public function instantSave()
{
if ($this->is_static) {
if ($this->isStatic) {
$this->port = 80;
$this->publish_directory = '/dist';
} else {
@ -126,12 +126,7 @@ public function instantSave()
$this->dispatch('success', 'Application settings updated!');
}
public function load_any_git()
{
$this->branch_found = true;
}
public function load_branch()
public function loadBranch()
{
try {
if (str($this->repository_url)->startsWith('git@')) {
@ -155,15 +150,15 @@ public function load_branch()
return handleError($e, $this);
}
try {
$this->branch_found = false;
$this->get_git_source();
$this->get_branch();
$this->selected_branch = $this->git_branch;
$this->branchFound = false;
$this->getGitSource();
$this->getBranch();
$this->selectedBranch = $this->git_branch;
} catch (\Throwable $e) {
if (! $this->branch_found && $this->git_branch == 'main') {
if (! $this->branchFound && $this->git_branch == 'main') {
try {
$this->git_branch = 'master';
$this->get_branch();
$this->getBranch();
} catch (\Throwable $e) {
return handleError($e, $this);
}
@ -173,13 +168,16 @@ public function load_branch()
}
}
private function get_git_source()
private function getGitSource()
{
$this->repository_url_parsed = Url::fromString($this->repository_url);
$this->git_host = $this->repository_url_parsed->getHost();
$this->git_repository = $this->repository_url_parsed->getSegment(1).'/'.$this->repository_url_parsed->getSegment(2);
$this->git_branch = $this->repository_url_parsed->getSegment(4) ?? 'main';
if ($this->repository_url_parsed->getSegment(3) === 'tree') {
$this->git_branch = str($this->repository_url_parsed->getPath())->after('tree/')->value();
} else {
$this->git_branch = 'main';
}
if ($this->git_host == 'github.com') {
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
@ -189,17 +187,17 @@ private function get_git_source()
$this->git_source = 'other';
}
private function get_branch()
private function getBranch()
{
if ($this->git_source === 'other') {
$this->branch_found = true;
$this->branchFound = true;
return;
}
if ($this->git_source->getMorphClass() === 'App\Models\GithubApp') {
['rate_limit_remaining' => $this->rate_limit_remaining, 'rate_limit_reset' => $this->rate_limit_reset] = githubApi(source: $this->git_source, endpoint: "/repos/{$this->git_repository}/branches/{$this->git_branch}");
$this->rate_limit_reset = Carbon::parse((int) $this->rate_limit_reset)->format('Y-M-d H:i:s');
$this->branch_found = true;
$this->branchFound = true;
}
}
@ -287,7 +285,7 @@ public function submit()
}
$application = Application::create($application_init);
$application->settings->is_static = $this->is_static;
$application->settings->is_static = $this->isStatic;
$application->settings->save();
$fqdn = generateFqdn($destination->server, $application->uuid);

View File

@ -1,7 +1,7 @@
<div>
<h1>Create a new Application</h1>
<div class="pb-4">Deploy any public Git repositories.</div>
<form class="flex flex-col gap-2" wire:submit='load_branch'>
<form class="flex flex-col gap-2" wire:submit='loadBranch'>
<div class="flex flex-col gap-2">
<div class="flex flex-col gap-2">
<div class="flex items-end gap-2">
@ -11,7 +11,7 @@
Check repository
</x-forms.button>
</div>
@if (!$branch_found)
@if (!$branchFound)
<div class="px-2 pt-4">
<div>
For example application deployments, checkout <a class="underline dark:text-white"
@ -19,7 +19,7 @@
Examples</a>.
</div>
@endif
@if ($branch_found)
@if ($branchFound)
@if ($rate_limit_remaining && $rate_limit_reset)
<div class="flex gap-2 py-2">
<div>Rate Limit</div>
@ -42,7 +42,7 @@
<option value="dockerfile">Dockerfile</option>
<option value="dockercompose">Docker Compose</option>
</x-forms.select>
@if ($is_static)
@if ($isStatic)
<x-forms.input id="publish_directory" label="Publish Directory"
helper="If there is a build process involved (like Svelte, React, Next, etc..), please specify the output directory for the build assets." />
@endif
@ -57,10 +57,10 @@
class='dark:text-warning'>{{ Str::start($base_directory . $docker_compose_location, '/') }}</span>
@endif
@if ($show_is_static)
<x-forms.input type="number" id="port" label="Port" :readonly="$is_static || $build_pack === 'static'"
<x-forms.input type="number" id="port" label="Port" :readonly="$isStatic || $build_pack === 'static'"
helper="The port your application listens on." />
<div class="w-52">
<x-forms.checkbox instantSave id="is_static" label="Is it a static site?"
<x-forms.checkbox instantSave id="isStatic" label="Is it a static site?"
helper="If your application is a static site or the final build assets should be served as a static site, enable this." />
</div>
@endif