Skip to content

Commit 04b35f8

Browse files
simonhampclaude
andauthored
Fix "View on GitHub" link to use repository URL instead of package name (#293)
The getGithubUrl() method was constructing a URL from the Composer package name (vendor/package), which doesn't necessarily match the actual GitHub repository URL. Changed it to return the stored repository_url directly. Also hides the action when no repository URL is set. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a4aceea commit 04b35f8

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

app/Filament/Resources/PluginResource/Pages/EditPlugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ protected function getHeaderActions(): array
248248
->label('View on GitHub')
249249
->icon('heroicon-o-arrow-top-right-on-square')
250250
->color('gray')
251+
->visible(fn () => $this->record->repository_url !== null)
251252
->url(fn () => $this->record->getGithubUrl())
252253
->openUrlInNewTab(),
253254
])

app/Models/Plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ public function getPackagistUrl(): string
315315
return "https://packagist.org/packages/{$this->name}";
316316
}
317317

318-
public function getGithubUrl(): string
318+
public function getGithubUrl(): ?string
319319
{
320-
return "https://github.com/{$this->name}";
320+
return $this->repository_url;
321321
}
322322

323323
public function getWebhookUrl(): ?string

tests/Feature/Filament/ResyncPluginActionTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,27 @@ public function test_resync_action_hidden_when_no_repository_url(): void
6464
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
6565
->assertActionHidden('resync');
6666
}
67+
68+
public function test_view_github_action_uses_repository_url(): void
69+
{
70+
$plugin = Plugin::factory()->free()->approved()->create([
71+
'repository_url' => 'https://github.com/acme/test-plugin',
72+
]);
73+
74+
Livewire::actingAs($this->admin)
75+
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
76+
->assertActionVisible('viewGithub')
77+
->assertActionHasUrl('viewGithub', 'https://github.com/acme/test-plugin');
78+
}
79+
80+
public function test_view_github_action_hidden_when_no_repository_url(): void
81+
{
82+
$plugin = Plugin::factory()->free()->approved()->create([
83+
'repository_url' => null,
84+
]);
85+
86+
Livewire::actingAs($this->admin)
87+
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
88+
->assertActionHidden('viewGithub');
89+
}
6790
}

0 commit comments

Comments
 (0)