fix: handle / in preselecting branches
This commit is contained in:
parent
997a262b6c
commit
4c031a7c05
@ -25,11 +25,11 @@ class PublicGitRepository extends Component
|
|||||||
|
|
||||||
public $query;
|
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;
|
public ?string $publish_directory = null;
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ class PublicGitRepository extends Component
|
|||||||
protected $rules = [
|
protected $rules = [
|
||||||
'repository_url' => 'required|url',
|
'repository_url' => 'required|url',
|
||||||
'port' => 'required|numeric',
|
'port' => 'required|numeric',
|
||||||
'is_static' => 'required|boolean',
|
'isStatic' => 'required|boolean',
|
||||||
'publish_directory' => 'nullable|string',
|
'publish_directory' => 'nullable|string',
|
||||||
'build_pack' => 'required|string',
|
'build_pack' => 'required|string',
|
||||||
'base_directory' => 'nullable|string',
|
'base_directory' => 'nullable|string',
|
||||||
@ -72,7 +72,7 @@ class PublicGitRepository extends Component
|
|||||||
protected $validationAttributes = [
|
protected $validationAttributes = [
|
||||||
'repository_url' => 'repository',
|
'repository_url' => 'repository',
|
||||||
'port' => 'port',
|
'port' => 'port',
|
||||||
'is_static' => 'static',
|
'isStatic' => 'static',
|
||||||
'publish_directory' => 'publish directory',
|
'publish_directory' => 'publish directory',
|
||||||
'build_pack' => 'build pack',
|
'build_pack' => 'build pack',
|
||||||
'base_directory' => 'base directory',
|
'base_directory' => 'base directory',
|
||||||
@ -106,17 +106,17 @@ public function updatedBuildPack()
|
|||||||
$this->port = 3000;
|
$this->port = 3000;
|
||||||
} elseif ($this->build_pack === 'static') {
|
} elseif ($this->build_pack === 'static') {
|
||||||
$this->show_is_static = false;
|
$this->show_is_static = false;
|
||||||
$this->is_static = false;
|
$this->isStatic = false;
|
||||||
$this->port = 80;
|
$this->port = 80;
|
||||||
} else {
|
} else {
|
||||||
$this->show_is_static = false;
|
$this->show_is_static = false;
|
||||||
$this->is_static = false;
|
$this->isStatic = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function instantSave()
|
public function instantSave()
|
||||||
{
|
{
|
||||||
if ($this->is_static) {
|
if ($this->isStatic) {
|
||||||
$this->port = 80;
|
$this->port = 80;
|
||||||
$this->publish_directory = '/dist';
|
$this->publish_directory = '/dist';
|
||||||
} else {
|
} else {
|
||||||
@ -126,12 +126,7 @@ public function instantSave()
|
|||||||
$this->dispatch('success', 'Application settings updated!');
|
$this->dispatch('success', 'Application settings updated!');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load_any_git()
|
public function loadBranch()
|
||||||
{
|
|
||||||
$this->branch_found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load_branch()
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (str($this->repository_url)->startsWith('git@')) {
|
if (str($this->repository_url)->startsWith('git@')) {
|
||||||
@ -155,15 +150,15 @@ public function load_branch()
|
|||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$this->branch_found = false;
|
$this->branchFound = false;
|
||||||
$this->get_git_source();
|
$this->getGitSource();
|
||||||
$this->get_branch();
|
$this->getBranch();
|
||||||
$this->selected_branch = $this->git_branch;
|
$this->selectedBranch = $this->git_branch;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
if (! $this->branch_found && $this->git_branch == 'main') {
|
if (! $this->branchFound && $this->git_branch == 'main') {
|
||||||
try {
|
try {
|
||||||
$this->git_branch = 'master';
|
$this->git_branch = 'master';
|
||||||
$this->get_branch();
|
$this->getBranch();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return handleError($e, $this);
|
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->repository_url_parsed = Url::fromString($this->repository_url);
|
||||||
$this->git_host = $this->repository_url_parsed->getHost();
|
$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_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') {
|
if ($this->git_host == 'github.com') {
|
||||||
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
|
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
|
||||||
|
|
||||||
@ -189,17 +187,17 @@ private function get_git_source()
|
|||||||
$this->git_source = 'other';
|
$this->git_source = 'other';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_branch()
|
private function getBranch()
|
||||||
{
|
{
|
||||||
if ($this->git_source === 'other') {
|
if ($this->git_source === 'other') {
|
||||||
$this->branch_found = true;
|
$this->branchFound = true;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($this->git_source->getMorphClass() === 'App\Models\GithubApp') {
|
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}");
|
['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->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 = Application::create($application_init);
|
||||||
|
|
||||||
$application->settings->is_static = $this->is_static;
|
$application->settings->is_static = $this->isStatic;
|
||||||
$application->settings->save();
|
$application->settings->save();
|
||||||
|
|
||||||
$fqdn = generateFqdn($destination->server, $application->uuid);
|
$fqdn = generateFqdn($destination->server, $application->uuid);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<h1>Create a new Application</h1>
|
<h1>Create a new Application</h1>
|
||||||
<div class="pb-4">Deploy any public Git repositories.</div>
|
<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 flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<div class="flex items-end gap-2">
|
<div class="flex items-end gap-2">
|
||||||
@ -11,7 +11,7 @@
|
|||||||
Check repository
|
Check repository
|
||||||
</x-forms.button>
|
</x-forms.button>
|
||||||
</div>
|
</div>
|
||||||
@if (!$branch_found)
|
@if (!$branchFound)
|
||||||
<div class="px-2 pt-4">
|
<div class="px-2 pt-4">
|
||||||
<div>
|
<div>
|
||||||
For example application deployments, checkout <a class="underline dark:text-white"
|
For example application deployments, checkout <a class="underline dark:text-white"
|
||||||
@ -19,7 +19,7 @@
|
|||||||
Examples</a>.
|
Examples</a>.
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@if ($branch_found)
|
@if ($branchFound)
|
||||||
@if ($rate_limit_remaining && $rate_limit_reset)
|
@if ($rate_limit_remaining && $rate_limit_reset)
|
||||||
<div class="flex gap-2 py-2">
|
<div class="flex gap-2 py-2">
|
||||||
<div>Rate Limit</div>
|
<div>Rate Limit</div>
|
||||||
@ -42,7 +42,7 @@
|
|||||||
<option value="dockerfile">Dockerfile</option>
|
<option value="dockerfile">Dockerfile</option>
|
||||||
<option value="dockercompose">Docker Compose</option>
|
<option value="dockercompose">Docker Compose</option>
|
||||||
</x-forms.select>
|
</x-forms.select>
|
||||||
@if ($is_static)
|
@if ($isStatic)
|
||||||
<x-forms.input id="publish_directory" label="Publish Directory"
|
<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." />
|
helper="If there is a build process involved (like Svelte, React, Next, etc..), please specify the output directory for the build assets." />
|
||||||
@endif
|
@endif
|
||||||
@ -57,10 +57,10 @@
|
|||||||
class='dark:text-warning'>{{ Str::start($base_directory . $docker_compose_location, '/') }}</span>
|
class='dark:text-warning'>{{ Str::start($base_directory . $docker_compose_location, '/') }}</span>
|
||||||
@endif
|
@endif
|
||||||
@if ($show_is_static)
|
@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." />
|
helper="The port your application listens on." />
|
||||||
<div class="w-52">
|
<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." />
|
helper="If your application is a static site or the final build assets should be served as a static site, enable this." />
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
Loading…
Reference in New Issue
Block a user