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>
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Repositories\Pages;
|
||||
|
||||
use App\Filament\Resources\Repositories\RepositoryResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateRepository extends CreateRecord
|
||||
{
|
||||
protected static string $resource = RepositoryResource::class;
|
||||
}
|
||||
24
app/Filament/Resources/Repositories/Pages/EditRepository.php
Normal file
24
app/Filament/Resources/Repositories/Pages/EditRepository.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Repositories\Pages;
|
||||
|
||||
use App\Filament\Concerns\WarnsOfConcurrentEditing;
|
||||
use App\Filament\Resources\Repositories\RepositoryResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditRepository extends EditRecord
|
||||
{
|
||||
use WarnsOfConcurrentEditing;
|
||||
|
||||
protected static string $resource = RepositoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Repositories\Pages;
|
||||
|
||||
use App\Filament\Resources\Repositories\RepositoryResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListRepositories extends ListRecords
|
||||
{
|
||||
protected static string $resource = RepositoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
135
app/Filament/Resources/Repositories/RepositoryResource.php
Normal file
135
app/Filament/Resources/Repositories/RepositoryResource.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Repositories;
|
||||
|
||||
use App\Enums\GitProvider;
|
||||
use App\Filament\Resources\Repositories\Pages\CreateRepository;
|
||||
use App\Filament\Resources\Repositories\Pages\EditRepository;
|
||||
use App\Filament\Resources\Repositories\Pages\ListRepositories;
|
||||
use App\Filament\Resources\Repositories\Tables\RepositoriesTable;
|
||||
use App\Models\Repository;
|
||||
use BackedEnum;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Git repositories connected to the collective's projects.
|
||||
*
|
||||
* The form is intentionally tiny: a repository is identified by its provider
|
||||
* and "owner/repo", and everything else — stars, languages, contributors,
|
||||
* newcomer-friendly issues — arrives from the provider on each sync. Nothing
|
||||
* synced is editable, because a hand-typed star count is a lie waiting to
|
||||
* happen.
|
||||
*/
|
||||
class RepositoryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Repository::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCodeBracketSquare;
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'full_name';
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('panel.repositories.label');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('panel.repositories.plural');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): string|UnitEnum|null
|
||||
{
|
||||
return __('panel.groups.collective');
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Section::make()
|
||||
->columns(2)
|
||||
->schema([
|
||||
Select::make('provider')
|
||||
->label(__('panel.repositories.fields.provider'))
|
||||
->options(GitProvider::class)
|
||||
->default(GitProvider::default())
|
||||
->required()
|
||||
// Only providers with a driver registered in
|
||||
// config/git.php can actually be synced.
|
||||
->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)
|
||||
->rules(['regex:/^[\w.-]+\/[\w.-]+$|^[\w.-]+$/']),
|
||||
|
||||
Select::make('project_id')
|
||||
->label(__('panel.repositories.fields.project'))
|
||||
->relationship('project', 'title->'.config('locales.default'))
|
||||
->searchable()
|
||||
->preload(),
|
||||
|
||||
Toggle::make('is_primary')
|
||||
->label(__('panel.repositories.fields.is_primary'))
|
||||
->helperText(__('panel.repositories.fields.is_primary_hint')),
|
||||
|
||||
Toggle::make('show_publicly')
|
||||
->label(__('panel.repositories.fields.show_publicly'))
|
||||
->default(true),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return RepositoriesTable::configure($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['full_name'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListRepositories::route('/'),
|
||||
'create' => CreateRepository::route('/create'),
|
||||
'edit' => EditRepository::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags repositories whose sync keeps failing — usually renamed or deleted
|
||||
* upstream — so stale numbers do not sit on the public site unnoticed.
|
||||
*/
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
$failing = static::getModel()::query()->failing()->count();
|
||||
|
||||
return $failing > 0 ? (string) $failing : null;
|
||||
}
|
||||
|
||||
public static function getNavigationBadgeColor(): ?string
|
||||
{
|
||||
return 'danger';
|
||||
}
|
||||
}
|
||||
178
app/Filament/Resources/Repositories/Tables/RepositoriesTable.php
Normal file
178
app/Filament/Resources/Repositories/Tables/RepositoriesTable.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Repositories\Tables;
|
||||
|
||||
use App\Jobs\SyncRepository;
|
||||
use App\Models\Repository;
|
||||
use App\Services\Git\GitException;
|
||||
use App\Services\Git\GitManager;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RepositoriesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('stars', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('full_name')
|
||||
->label(__('panel.repositories.fields.full_name'))
|
||||
->weight('medium')
|
||||
->description(fn (Repository $r) => $r->description)
|
||||
->wrap()
|
||||
->url(fn (Repository $r) => $r->html_url, shouldOpenInNewTab: true)
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('project.title')
|
||||
->label(__('panel.repositories.fields.project'))
|
||||
->badge()
|
||||
->color('gray')
|
||||
->placeholder('—')
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('primary_language')
|
||||
->label(__('panel.repositories.fields.language'))
|
||||
->badge()
|
||||
->placeholder('—'),
|
||||
|
||||
TextColumn::make('stars')
|
||||
->label('★')
|
||||
->badge()
|
||||
->color('warning')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('contributors_count')
|
||||
->label(__('panel.repositories.fields.contributors'))
|
||||
->badge()
|
||||
->color('gray')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('good_first_issues_count')
|
||||
->label(__('panel.repositories.fields.good_first_issues'))
|
||||
->counts('goodFirstIssues')
|
||||
->badge()
|
||||
->color(fn ($state) => $state > 0 ? 'success' : 'gray'),
|
||||
|
||||
TextColumn::make('pushed_at')
|
||||
->label(__('panel.repositories.fields.pushed_at'))
|
||||
->since()
|
||||
// A repository nobody has touched in months is worth
|
||||
// spotting: it is what makes a site look abandoned.
|
||||
->color(fn (Repository $r) => $r->isDormant() ? 'danger' : null)
|
||||
->placeholder('—')
|
||||
->sortable(),
|
||||
|
||||
IconColumn::make('show_publicly')
|
||||
->label(__('panel.repositories.fields.show_publicly'))
|
||||
->boolean()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('last_synced_at')
|
||||
->label(__('panel.repositories.fields.last_synced_at'))
|
||||
->since()
|
||||
->description(fn (Repository $r) => $r->sync_error
|
||||
? str($r->sync_error)->limit(60)->toString()
|
||||
: null)
|
||||
->color(fn (Repository $r) => $r->sync_error ? 'danger' : 'gray')
|
||||
->placeholder(__('panel.repositories.never_synced')),
|
||||
])
|
||||
->filters([
|
||||
TernaryFilter::make('show_publicly')
|
||||
->label(__('panel.repositories.fields.show_publicly')),
|
||||
|
||||
Filter::make('failing')
|
||||
->label(__('panel.repositories.filters.failing'))
|
||||
->query(fn (Builder $q) => $q->failing()),
|
||||
|
||||
Filter::make('dormant')
|
||||
->label(__('panel.repositories.filters.dormant'))
|
||||
->query(fn (Builder $q) => $q->where(fn (Builder $sub) => $sub
|
||||
->whereNull('pushed_at')
|
||||
->orWhere('pushed_at', '<', now()->subDays(180)))),
|
||||
])
|
||||
->recordActions([
|
||||
self::syncAction(),
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
self::syncBulkAction(),
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs inline rather than queueing, so the person who clicked sees the
|
||||
* result — including the reason when it fails.
|
||||
*/
|
||||
protected static function syncAction(): Action
|
||||
{
|
||||
return 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 {
|
||||
$record = $git->sync($record);
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title(__('panel.repositories.notifications.synced'))
|
||||
->body(__('panel.repositories.notifications.synced_body', [
|
||||
'stars' => $record->stars,
|
||||
'issues' => $record->goodFirstIssues()->count(),
|
||||
]))
|
||||
->send();
|
||||
} catch (GitException $e) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title(__('panel.repositories.notifications.sync_failed'))
|
||||
->body($e->getMessage())
|
||||
->persistent()
|
||||
->send();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncing many repositories at once can exhaust the provider's rate limit,
|
||||
* so this one goes through the queue instead of blocking the request.
|
||||
*/
|
||||
protected static function syncBulkAction(): BulkAction
|
||||
{
|
||||
return BulkAction::make('syncAll')
|
||||
->label(__('panel.repositories.actions.sync_selected'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->requiresConfirmation()
|
||||
->visible(fn () => Auth::user()?->can('repositories.sync'))
|
||||
->action(function (Collection $records): void {
|
||||
$records->each(fn (Repository $r) => SyncRepository::dispatch($r));
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title(__('panel.repositories.notifications.queued', ['count' => $records->count()]))
|
||||
->send();
|
||||
})
|
||||
->deselectRecordsAfterCompletion();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user