An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(github): reset branch state when refreshing repositories
Andras Bacsai7638912fdc56
diff --git a/app/Livewire/Project/New/GithubPrivateRepository.php b/app/Livewire/Project/New/GithubPrivateRepository.phpindex 6aa8db0859..9d4acb9bb6 100644--- a/app/Livewire/Project/New/GithubPrivateRepository.php+++ b/app/Livewire/Project/New/GithubPrivateRepository.php@@ -99,6 +99,8 @@ class GithubPrivateRepository extends Componentpublic function loadRepositories($github_app_id){$this->repositories = collect();+ $this->branches = collect();+ $this->total_branches_count = 0;$this->page = 1;$this->selected_github_app_id = $github_app_id;$this->github_app = GithubApp::where('id', $github_app_id)->first();diff --git a/resources/views/livewire/project/new/github-private-repository.blade.php b/resources/views/livewire/project/new/github-private-repository.blade.phpindex 27ef6a189a..ec0d175069 100644--- a/resources/views/livewire/project/new/github-private-repository.blade.php+++ b/resources/views/livewire/project/new/github-private-repository.blade.php@@ -4,27 +4,18 @@<x-modal-input buttonTitle="+ Add GitHub App" title="New GitHub App" closeOutside="false"><livewire:source.github.create /></x-modal-input>+ @if ($repositories->count() > 0)+ <x-forms.button wire:click.prevent="loadRepositories({{ $github_app->id }})">+ Refresh Repository List+ </x-forms.button>+ <a target="_blank" class="inline-flex items-center self-center gap-1 text-sm hover:underline dark:text-neutral-400"+ href="{{ getInstallationPath($github_app) }}">+ Change Repositories on GitHub+ <x-external-link />+ </a>+ @endif</div><div class="pb-4">Deploy any public or private Git repositories through a GitHub App.</div>- @if ($repositories->count() > 0)- <div class="flex items-center gap-2 pb-4">- <a target="_blank" class="flex hover:no-underline" href="{{ getInstallationPath($github_app) }}">- <x-forms.button>- Change Repositories on GitHub- <x-external-link />- </x-forms.button>- </a>- <x-forms.button :showLoadingIndicator="false" wire:click.prevent="loadRepositories({{ $github_app->id }})" title="Refresh Repository List">- <svg class="w-4 h-4" wire:loading.remove wire:target="loadRepositories({{ $github_app->id }})" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">- <path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99" />- </svg>- <svg class="w-4 h-4 animate-spin" wire:loading wire:target="loadRepositories({{ $github_app->id }})" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">- <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>- <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>- </svg>- </x-forms.button>- </div>- @endif@if ($github_apps->count() !== 0)<div class="flex flex-col gap-2">@if ($current_step === 'github_apps')@@ -62,7 +53,10 @@@endforeach</x-forms.datalist></div>- <x-forms.button wire:click.prevent="loadBranches"> Load Repository </x-forms.button>+ <x-forms.button :showLoadingIndicator="false" wire:click.prevent="loadBranches" wire:target="loadBranches, selected_repository_id">+ Load Repository+ <x-loading-on-button wire:loading.delay wire:target="loadBranches, selected_repository_id" />+ </x-forms.button></div>@else<div>No repositories found. Check your GitHub App configuration.</div>diff --git a/tests/Feature/GithubPrivateRepositoryTest.php b/tests/Feature/GithubPrivateRepositoryTest.phpindex 19474caca4..abc288519f 100644--- a/tests/Feature/GithubPrivateRepositoryTest.php+++ b/tests/Feature/GithubPrivateRepositoryTest.php@@ -31,7 +31,7 @@ beforeEach(function () {'team_id' => $this->team->id,]);- $this->githubApp = GithubApp::create([+ $this->githubApp = GithubApp::forceCreate(['name' => 'Test GitHub App','api_url' => 'https://api.github.com','html_url' => 'https://github.com',@@ -86,25 +86,63 @@ describe('GitHub Private Repository Component', function () {['id' => 1, 'name' => 'alpha-repo', 'owner' => ['login' => 'testuser']],];- fakeGithubHttp($initialRepos);+ $updatedRepos = [+ ['id' => 1, 'name' => 'alpha-repo', 'owner' => ['login' => 'testuser']],+ ['id' => 2, 'name' => 'beta-repo', 'owner' => ['login' => 'testuser']],+ ['id' => 3, 'name' => 'gamma-repo', 'owner' => ['login' => 'testuser']],+ ];++ $callCount = 0;+ Http::fake([+ 'https://api.github.com/zen' => Http::response('Keep it logically awesome.', 200, [+ 'Date' => now()->toRfc7231String(),+ ]),+ 'https://api.github.com/app/installations/67890/access_tokens' => Http::response([+ 'token' => 'fake-installation-token',+ ], 201),+ 'https://api.github.com/installation/repositories*' => function () use (&$callCount, $initialRepos, $updatedRepos) {+ $callCount++;+ $repos = $callCount === 1 ? $initialRepos : $updatedRepos;++ return Http::response([+ 'total_count' => count($repos),+ 'repositories' => $repos,+ ], 200);+ },+ ]);$component = Livewire::test(GithubPrivateRepository::class, ['type' => 'private-gh-app'])->call('loadRepositories', $this->githubApp->id)->assertSet('total_repositories_count', 1);// Simulate new repos becoming available after changing access on GitHub- $updatedRepos = [+ $component+ ->call('loadRepositories', $this->githubApp->id)+ ->assertSet('total_repositories_count', 3)+ ->assertSet('current_step', 'repository');+ });++ test('loadRepositories resets branches when refreshing', function () {+ $repos = [['id' => 1, 'name' => 'alpha-repo', 'owner' => ['login' => 'testuser']],- ['id' => 2, 'name' => 'beta-repo', 'owner' => ['login' => 'testuser']],- ['id' => 3, 'name' => 'gamma-repo', 'owner' => ['login' => 'testuser']],];- fakeGithubHttp($updatedRepos);+ fakeGithubHttp($repos);++ $component = Livewire::test(GithubPrivateRepository::class, ['type' => 'private-gh-app'])+ ->call('loadRepositories', $this->githubApp->id);++ // Manually set branches to simulate a previous branch load+ $component->set('branches', collect([['name' => 'main'], ['name' => 'develop']]));+ $component->set('total_branches_count', 2);++ // Refresh repositories should reset branches+ fakeGithubHttp($repos);$component->call('loadRepositories', $this->githubApp->id)- ->assertSet('total_repositories_count', 3)- ->assertSet('current_step', 'repository');+ ->assertSet('total_branches_count', 0)+ ->assertSet('branches', collect());});test('refresh button is visible when repositories are loaded', function () {@@ -116,11 +154,11 @@ describe('GitHub Private Repository Component', function () {Livewire::test(GithubPrivateRepository::class, ['type' => 'private-gh-app'])->call('loadRepositories', $this->githubApp->id)- ->assertSeeHtml('title="Refresh Repository List"');+ ->assertSee('Refresh Repository List');});test('refresh button is not visible before repositories are loaded', function () {Livewire::test(GithubPrivateRepository::class, ['type' => 'private-gh-app'])- ->assertDontSeeHtml('title="Refresh Repository List"');+ ->assertDontSee('Refresh Repository List');});});