diff --git a/app/Filament/Resources/PluginResource/Pages/EditPlugin.php b/app/Filament/Resources/PluginResource/Pages/EditPlugin.php index dcb2cd4b..c8f40df0 100644 --- a/app/Filament/Resources/PluginResource/Pages/EditPlugin.php +++ b/app/Filament/Resources/PluginResource/Pages/EditPlugin.php @@ -248,6 +248,7 @@ protected function getHeaderActions(): array ->label('View on GitHub') ->icon('heroicon-o-arrow-top-right-on-square') ->color('gray') + ->visible(fn () => $this->record->repository_url !== null) ->url(fn () => $this->record->getGithubUrl()) ->openUrlInNewTab(), ]) diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index 7a8e07a4..0cf8e074 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -315,9 +315,9 @@ public function getPackagistUrl(): string return "https://packagist.org/packages/{$this->name}"; } - public function getGithubUrl(): string + public function getGithubUrl(): ?string { - return "https://github.com/{$this->name}"; + return $this->repository_url; } public function getWebhookUrl(): ?string diff --git a/tests/Feature/Filament/ResyncPluginActionTest.php b/tests/Feature/Filament/ResyncPluginActionTest.php index 8b131da4..76dba0d7 100644 --- a/tests/Feature/Filament/ResyncPluginActionTest.php +++ b/tests/Feature/Filament/ResyncPluginActionTest.php @@ -64,4 +64,27 @@ public function test_resync_action_hidden_when_no_repository_url(): void ->test(EditPlugin::class, ['record' => $plugin->getRouteKey()]) ->assertActionHidden('resync'); } + + public function test_view_github_action_uses_repository_url(): void + { + $plugin = Plugin::factory()->free()->approved()->create([ + 'repository_url' => 'https://github.com/acme/test-plugin', + ]); + + Livewire::actingAs($this->admin) + ->test(EditPlugin::class, ['record' => $plugin->getRouteKey()]) + ->assertActionVisible('viewGithub') + ->assertActionHasUrl('viewGithub', 'https://github.com/acme/test-plugin'); + } + + public function test_view_github_action_hidden_when_no_repository_url(): void + { + $plugin = Plugin::factory()->free()->approved()->create([ + 'repository_url' => null, + ]); + + Livewire::actingAs($this->admin) + ->test(EditPlugin::class, ['record' => $plugin->getRouteKey()]) + ->assertActionHidden('viewGithub'); + } }