Skip to content

Commit 4c031a7

Browse files
committed
fix: handle / in preselecting branches
1 parent 997a262 commit 4c031a7

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

app/Livewire/Project/New/PublicGitRepository.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class PublicGitRepository extends Component
2525

2626
public $query;
2727

28-
public bool $branch_found = false;
28+
public bool $branchFound = false;
2929

30-
public string $selected_branch = 'main';
30+
public string $selectedBranch = 'main';
3131

32-
public bool $is_static = false;
32+
public bool $isStatic = false;
3333

3434
public ?string $publish_directory = null;
3535

@@ -62,7 +62,7 @@ class PublicGitRepository extends Component
6262
protected $rules = [
6363
'repository_url' => 'required|url',
6464
'port' => 'required|numeric',
65-
'is_static' => 'required|boolean',
65+
'isStatic' => 'required|boolean',
6666
'publish_directory' => 'nullable|string',
6767
'build_pack' => 'required|string',
6868
'base_directory' => 'nullable|string',
@@ -72,7 +72,7 @@ class PublicGitRepository extends Component
7272
protected $validationAttributes = [
7373
'repository_url' => 'repository',
7474
'port' => 'port',
75-
'is_static' => 'static',
75+
'isStatic' => 'static',
7676
'publish_directory' => 'publish directory',
7777
'build_pack' => 'build pack',
7878
'base_directory' => 'base directory',
@@ -106,17 +106,17 @@ public function updatedBuildPack()
106106
$this->port = 3000;
107107
} elseif ($this->build_pack === 'static') {
108108
$this->show_is_static = false;
109-
$this->is_static = false;
109+
$this->isStatic = false;
110110
$this->port = 80;
111111
} else {
112112
$this->show_is_static = false;
113-
$this->is_static = false;
113+
$this->isStatic = false;
114114
}
115115
}
116116

117117
public function instantSave()
118118
{
119-
if ($this->is_static) {
119+
if ($this->isStatic) {
120120
$this->port = 80;
121121
$this->publish_directory = '/dist';
122122
} else {
@@ -126,12 +126,7 @@ public function instantSave()
126126
$this->dispatch('success', 'Application settings updated!');
127127
}
128128

129-
public function load_any_git()
130-
{
131-
$this->branch_found = true;
132-
}
133-
134-
public function load_branch()
129+
public function loadBranch()
135130
{
136131
try {
137132
if (str($this->repository_url)->startsWith('git@')) {
@@ -155,15 +150,15 @@ public function load_branch()
155150
return handleError($e, $this);
156151
}
157152
try {
158-
$this->branch_found = false;
159-
$this->get_git_source();
160-
$this->get_branch();
161-
$this->selected_branch = $this->git_branch;
153+
$this->branchFound = false;
154+
$this->getGitSource();
155+
$this->getBranch();
156+
$this->selectedBranch = $this->git_branch;
162157
} catch (\Throwable $e) {
163-
if (! $this->branch_found && $this->git_branch == 'main') {
158+
if (! $this->branchFound && $this->git_branch == 'main') {
164159
try {
165160
$this->git_branch = 'master';
166-
$this->get_branch();
161+
$this->getBranch();
167162
} catch (\Throwable $e) {
168163
return handleError($e, $this);
169164
}
@@ -173,13 +168,16 @@ public function load_branch()
173168
}
174169
}
175170

176-
private function get_git_source()
171+
private function getGitSource()
177172
{
178173
$this->repository_url_parsed = Url::fromString($this->repository_url);
179174
$this->git_host = $this->repository_url_parsed->getHost();
180175
$this->git_repository = $this->repository_url_parsed->getSegment(1).'/'.$this->repository_url_parsed->getSegment(2);
181-
$this->git_branch = $this->repository_url_parsed->getSegment(4) ?? 'main';
182-
176+
if ($this->repository_url_parsed->getSegment(3) === 'tree') {
177+
$this->git_branch = str($this->repository_url_parsed->getPath())->after('tree/')->value();
178+
} else {
179+
$this->git_branch = 'main';
180+
}
183181
if ($this->git_host == 'github.com') {
184182
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
185183

@@ -189,17 +187,17 @@ private function get_git_source()
189187
$this->git_source = 'other';
190188
}
191189

192-
private function get_branch()
190+
private function getBranch()
193191
{
194192
if ($this->git_source === 'other') {
195-
$this->branch_found = true;
193+
$this->branchFound = true;
196194

197195
return;
198196
}
199197
if ($this->git_source->getMorphClass() === 'App\Models\GithubApp') {
200198
['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}");
201199
$this->rate_limit_reset = Carbon::parse((int) $this->rate_limit_reset)->format('Y-M-d H:i:s');
202-
$this->branch_found = true;
200+
$this->branchFound = true;
203201
}
204202
}
205203

@@ -287,7 +285,7 @@ public function submit()
287285
}
288286
$application = Application::create($application_init);
289287

290-
$application->settings->is_static = $this->is_static;
288+
$application->settings->is_static = $this->isStatic;
291289
$application->settings->save();
292290

293291
$fqdn = generateFqdn($destination->server, $application->uuid);

resources/views/livewire/project/new/public-git-repository.blade.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div>
22
<h1>Create a new Application</h1>
33
<div class="pb-4">Deploy any public Git repositories.</div>
4-
<form class="flex flex-col gap-2" wire:submit='load_branch'>
4+
<form class="flex flex-col gap-2" wire:submit='loadBranch'>
55
<div class="flex flex-col gap-2">
66
<div class="flex flex-col gap-2">
77
<div class="flex items-end gap-2">
@@ -11,15 +11,15 @@
1111
Check repository
1212
</x-forms.button>
1313
</div>
14-
@if (!$branch_found)
14+
@if (!$branchFound)
1515
<div class="px-2 pt-4">
1616
<div>
1717
For example application deployments, checkout <a class="underline dark:text-white"
1818
href="https://github.com/coollabsio/coolify-examples/" target="_blank">Coolify
1919
Examples</a>.
2020
</div>
2121
@endif
22-
@if ($branch_found)
22+
@if ($branchFound)
2323
@if ($rate_limit_remaining && $rate_limit_reset)
2424
<div class="flex gap-2 py-2">
2525
<div>Rate Limit</div>
@@ -42,7 +42,7 @@
4242
<option value="dockerfile">Dockerfile</option>
4343
<option value="dockercompose">Docker Compose</option>
4444
</x-forms.select>
45-
@if ($is_static)
45+
@if ($isStatic)
4646
<x-forms.input id="publish_directory" label="Publish Directory"
4747
helper="If there is a build process involved (like Svelte, React, Next, etc..), please specify the output directory for the build assets." />
4848
@endif
@@ -57,10 +57,10 @@
5757
class='dark:text-warning'>{{ Str::start($base_directory . $docker_compose_location, '/') }}</span>
5858
@endif
5959
@if ($show_is_static)
60-
<x-forms.input type="number" id="port" label="Port" :readonly="$is_static || $build_pack === 'static'"
60+
<x-forms.input type="number" id="port" label="Port" :readonly="$isStatic || $build_pack === 'static'"
6161
helper="The port your application listens on." />
6262
<div class="w-52">
63-
<x-forms.checkbox instantSave id="is_static" label="Is it a static site?"
63+
<x-forms.checkbox instantSave id="isStatic" label="Is it a static site?"
6464
helper="If your application is a static site or the final build assets should be served as a static site, enable this." />
6565
</div>
6666
@endif

0 commit comments

Comments
 (0)