diff --git a/app/Livewire/Project/New/GithubPrivateRepository.php b/app/Livewire/Project/New/GithubPrivateRepository.php
index 6aa8db085..9d4acb9bb 100644
--- a/app/Livewire/Project/New/GithubPrivateRepository.php
+++ b/app/Livewire/Project/New/GithubPrivateRepository.php
@@ -99,6 +99,8 @@ public function updatedBuildPack()
public 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.php
index 27ef6a189..ec0d17506 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 @@
+ @if ($repositories->count() > 0)
+
+ Refresh Repository List
+
+
+ Change Repositories on GitHub
+
+
+ @endif
Deploy any public or private Git repositories through a GitHub App.
- @if ($repositories->count() > 0)
-
- @endif
@if ($github_apps->count() !== 0)
@if ($current_step === 'github_apps')
@@ -62,7 +53,10 @@
@endforeach
- Load Repository
+
+ Load Repository
+
+
@else
No repositories found. Check your GitHub App configuration.
diff --git a/tests/Feature/GithubPrivateRepositoryTest.php b/tests/Feature/GithubPrivateRepositoryTest.php
index 19474caca..abc288519 100644
--- a/tests/Feature/GithubPrivateRepositoryTest.php
+++ b/tests/Feature/GithubPrivateRepositoryTest.php
@@ -31,7 +31,7 @@
'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,27 +86,65 @@ function fakeGithubHttp(array $repositories): void
['id' => 1, 'name' => 'alpha-repo', 'owner' => ['login' => 'testuser']],
];
- fakeGithubHttp($initialRepos);
-
- $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 = [
['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);
+ $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
$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']],
+ ];
+
+ 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_branches_count', 0)
+ ->assertSet('branches', collect());
+ });
+
test('refresh button is visible when repositories are loaded', function () {
$repos = [
['id' => 1, 'name' => 'alpha-repo', 'owner' => ['login' => 'testuser']],
@@ -116,11 +154,11 @@ function fakeGithubHttp(array $repositories): void
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');
});
});