Files
landing-api/app/Filament/Resources/Projects/RelationManagers/RepositoriesRelationManager.php
Josep Piguillem 3897113313 Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer
collective, backed by the Pireon OAuth identity server. The public site is a
separate, server-rendered application consuming /api/public/v1.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 17:55:27 +02:00

137 lines
5.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Resources\Projects\RelationManagers;
use App\Enums\GitProvider;
use App\Models\Repository;
use App\Services\Git\GitException;
use App\Services\Git\GitManager;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Actions\DeleteAction;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
/**
* Connect repositories from inside a project, which is where the person adding
* them is already working.
*
* A newly attached repository is synced immediately so its stats appear at
* once, rather than staying blank until the hourly schedule runs.
*/
class RepositoriesRelationManager extends RelationManager
{
protected static string $relationship = 'repositories';
public static function getTitle(Model $ownerRecord, string $pageClass): string
{
return __('panel.repositories.plural');
}
public function form(Schema $schema): Schema
{
return $schema->components([
Select::make('provider')
->label(__('panel.repositories.fields.provider'))
->options(GitProvider::class)
->default(GitProvider::default())
->required()
->disableOptionWhen(fn (string $value) => ! GitProvider::from($value)->isSupported()),
TextInput::make('full_name')
->label(__('panel.repositories.fields.full_name'))
->placeholder('colectivo/mi-proyecto')
->helperText(__('panel.repositories.fields.full_name_hint'))
->required()
->maxLength(255),
Toggle::make('is_primary')
->label(__('panel.repositories.fields.is_primary')),
Toggle::make('show_publicly')
->label(__('panel.repositories.fields.show_publicly'))
->default(true),
]);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('full_name')
->columns([
TextColumn::make('full_name')
->label(__('panel.repositories.fields.full_name'))
->url(fn (Repository $r) => $r->html_url, shouldOpenInNewTab: true),
TextColumn::make('primary_language')
->label(__('panel.repositories.fields.language'))
->badge()
->placeholder('—'),
TextColumn::make('stars')->label('★')->badge()->color('warning'),
TextColumn::make('good_first_issues_count')
->label(__('panel.repositories.fields.good_first_issues'))
->counts('goodFirstIssues')
->badge(),
TextColumn::make('pushed_at')
->label(__('panel.repositories.fields.pushed_at'))
->since()
->color(fn (Repository $r) => $r->isDormant() ? 'danger' : null)
->placeholder('—'),
])
->headerActions([
CreateAction::make()
// Sync straight away so the stats are not blank until the
// next scheduled run.
->after(function (Repository $record, GitManager $git): void {
try {
$git->sync($record);
} catch (GitException $e) {
Notification::make()
->warning()
->title(__('panel.repositories.notifications.sync_failed'))
->body($e->getMessage())
->send();
}
}),
])
->recordActions([
Action::make('sync')
->label(__('panel.repositories.actions.sync'))
->icon('heroicon-o-arrow-path')
->color('gray')
->visible(fn () => Auth::user()?->can('repositories.sync'))
->action(function (Repository $record, GitManager $git): void {
try {
$git->sync($record);
Notification::make()
->success()
->title(__('panel.repositories.notifications.synced'))
->send();
} catch (GitException $e) {
Notification::make()
->danger()
->title(__('panel.repositories.notifications.sync_failed'))
->body($e->getMessage())
->send();
}
}),
DeleteAction::make(),
]);
}
}