tomatophp / filament-cms-github
Github integration to import your repo docs README files as a docs on markdown format to TomatoPHP CMS
Fund package maintenance!
3x1io
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/tomatophp/filament-cms-github
Requires
- php: ^8.2|^8.3|^8.4
- tomatophp/console-helpers: ^1.1
- tomatophp/filament-cms: ^4.0
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- pestphp/pest-plugin-livewire: ^3.0
- pestphp/pest-plugin-type-coverage: ^3.5
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
This package is auto-updated.
Last update: 2025-10-09 14:05:47 UTC
README
Filament CMS GitHub Integration
GitHub integration for TomatoPHP CMS that automatically imports and synchronizes GitHub repository documentation (README files) as posts in your CMS. Perfect for maintaining documentation sites, portfolio showcases, or open-source project listings.
Screenshot
Features
- ๐ Automatic Import - Import GitHub repositories with a single click
- ๐ README Sync - Automatically fetches and converts README.md to post content
- ๐ GitHub Stats - Imports stars, forks, watchers, and issue counts
- ๐ฆ Packagist Integration - Fetches download statistics for PHP packages
- ๐ Bulk Refresh - Update all imported repositories at once
- ๐จ Avatar Images - Automatically downloads repository owner avatars
- ๐ท๏ธ Auto Tagging - Extracts keywords from Packagist data
- โก Queue Support - Background processing for better performance
- ๐ Notifications - User notifications on import success/failure
- ๐งช Full Test Coverage - 39 comprehensive tests
Installation
Install the package via composer:
composer require tomatophp/filament-cms-github
Run the installation command:
php artisan filament-cms-github:install
Register the plugin in your Filament panel provider (/app/Providers/Filament/AdminPanelProvider.php
):
use TomatoPHP\FilamentCmsGithub\FilamentCmsGithubPlugin; public function panel(Panel $panel): Panel { return $panel ->plugin(FilamentCmsGithubPlugin::make()); }
Requirements
- PHP 8.2 or higher
- Laravel 10.x or 11.x
- Filament 3.x
- TomatoPHP CMS 4.x
Configuration
Queue Setup
This package dispatches jobs to the queue for better performance. Make sure your queue is configured:
# Run queue worker
php artisan queue:work
Post Type Configuration
Imported repositories are saved as posts with type open-source
. You can customize this in your CMS configuration.
Usage
Import Single Repository
- Navigate to your CMS Posts page in Filament
- Click the "Github Import" action button
- Enter repository URL(s) and redirect path(s)
- Click submit
Example:
URL: https://github.com/tomatophp/filament-cms
Redirect: /posts
Import Multiple Repositories
You can import multiple repositories at once:
URL | Redirect URL
-------------------------------------------- | ------------
https://github.com/tomatophp/filament-cms | /cms
https://github.com/tomatophp/filament-alerts| /alerts
https://github.com/tomatophp/filament-users | /users
Refresh All Repositories
To update all previously imported repositories with latest data:
- Use the "Refresh Github Links" action
- All posts with
type = 'open-source'
and ameta_url
will be updated
Programmatic Usage
Import Repository
use TomatoPHP\FilamentCmsGithub\Services\GitHubService; $service = app(GitHubService::class); $post = $service->importRepository( url: 'https://github.com/tomatophp/filament-cms', userId: auth()->id(), userType: get_class(auth()->user()) );
Refresh Existing Post
use TomatoPHP\FilamentCmsGithub\Services\GitHubService; use TomatoPHP\FilamentCms\Models\Post; $service = app(GitHubService::class); $post = Post::find(1); $success = $service->refreshPost($post);
Refresh All Posts
use TomatoPHP\FilamentCmsGithub\Services\GitHubService; $service = app(GitHubService::class); $count = $service->refreshAllPosts(); // Returns number of posts refreshed
API Reference
GitHubService
The main service class for GitHub operations.
extractRepoFromUrl(string $url): string
Extracts repository name from GitHub URL.
$repo = $service->extractRepoFromUrl('https://github.com/tomatophp/filament-cms'); // Returns: 'tomatophp/filament-cms'
fetchRepoData(string $repo): ?array
Fetches repository data from GitHub API.
$data = $service->fetchRepoData('tomatophp/filament-cms'); // Returns array with: id, name, full_name, description, stargazers_count, etc.
fetchReadme(string $repo, string $branch = 'main'): ?string
Fetches README content from repository.
$readme = $service->fetchReadme('tomatophp/filament-cms', 'master'); // Returns: markdown content as string
fetchPackagistData(string $packageName): ?array
Fetches package data from Packagist.
$data = $service->fetchPackagistData('tomatophp/filament-cms'); // Returns array with downloads, versions, keywords, etc.
importRepository(string $url, ?int $userId = null, ?string $userType = null): ?Post
Imports a complete repository as a post.
$post = $service->importRepository( url: 'https://github.com/tomatophp/filament-cms', userId: 1, userType: 'App\\Models\\User' );
refreshPost(Post $post): bool
Refreshes an existing post with latest GitHub data.
$success = $service->refreshPost($post);
refreshAllPosts(): int
Refreshes all posts of type 'open-source' with meta_url.
$count = $service->refreshAllPosts();
Filament Actions
GithubImportAction
Provides a Filament action for importing repositories.
use TomatoPHP\FilamentCmsGithub\Filament\Actions\GithubImportAction; // In your resource protected function getHeaderActions(): array { return [ GithubImportAction::make(), ]; }
GithubRefreshAction
Provides a Filament action for refreshing all repositories.
use TomatoPHP\FilamentCmsGithub\Filament\Actions\GithubRefreshAction; protected function getHeaderActions(): array { return [ GithubRefreshAction::make(), ]; }
Data Structure
Post Fields
Imported repositories are saved with the following structure:
[ 'title' => ['en' => 'Repository Name', 'ar' => 'Repository Name'], 'slug' => 'repository-name', 'body' => ['en' => '# README content...', 'ar' => '# README content...'], 'short_description' => ['en' => 'Description', 'ar' => 'Description'], 'keywords' => ['en' => 'keyword1,keyword2', 'ar' => 'keyword1,keyword2'], 'type' => 'open-source', 'meta_url' => 'https://github.com/owner/repo', 'is_published' => true, 'published_at' => now(), ]
Meta Fields
GitHub statistics are stored as meta fields:
github_starts
- Star countgithub_watchers
- Watcher countgithub_language
- Primary languagegithub_forks
- Fork countgithub_open_issues
- Open issue countgithub_default_branch
- Default branch namegithub_docs
- Homepage/documentation URLdownloads_total
- Total Packagist downloads (if available)downloads_monthly
- Monthly downloadsdownloads_daily
- Daily downloads
Accessing Meta Fields
$post = Post::find(1); // Get star count $stars = $post->meta('github_starts'); // Get total downloads $downloads = $post->meta('downloads_total');
Jobs
GitHubMetaGetterJob
Handles importing a single repository in the background.
use TomatoPHP\FilamentCmsGithub\Jobs\GitHubMetaGetterJob; dispatch(new GitHubMetaGetterJob( url: 'https://github.com/tomatophp/filament-cms', redirect: '/posts', userId: auth()->id(), userType: get_class(auth()->user()), panel: 'admin' ));
GitHubMetaRefreshJob
Handles refreshing all repositories in the background.
use TomatoPHP\FilamentCmsGithub\Jobs\GitHubMetaRefreshJob; dispatch(new GitHubMetaRefreshJob);
Events
The package dispatches the following events:
TomatoPHP\FilamentCms\Events\PostCreated
- When a repository is importedTomatoPHP\FilamentCms\Events\PostUpdated
- When a repository is refreshed
Notifications
Users receive notifications for:
- Import Success - Repository imported successfully with link to view post
- Import Failure - Repository import failed with error details
- Refresh Success - All repositories refreshed successfully
Testing
The package includes comprehensive test coverage:
# Run tests composer test # Run tests with coverage composer test-coverage # Run static analysis composer analyse # Format code composer format
Test Structure
- GitHubServiceTest (17 tests) - Tests all service methods
- GitHubActionsTest (13 tests) - Tests Filament actions
- GitHubJobsTest (7 tests) - Tests job execution
- PluginTest (1 test) - Tests plugin registration
Publish Assets
Config File
php artisan vendor:publish --tag="filament-cms-github-config"
Views
php artisan vendor:publish --tag="filament-cms-github-views"
Translations
php artisan vendor:publish --tag="filament-cms-github-lang"
Migrations
php artisan vendor:publish --tag="filament-cms-github-migrations"
Troubleshooting
Queue Not Processing
Make sure your queue worker is running:
php artisan queue:work
For development, you can use sync driver in .env
:
QUEUE_CONNECTION=sync
GitHub API Rate Limits
GitHub API has rate limits. For authenticated requests (recommended), generate a personal access token and configure it in your application.
README Not Found
The package tries multiple branch names automatically:
main
master
- Default branch from GitHub API
If README is not found, the post will be created with empty body content.
Advanced Usage
Custom Post Processing
You can listen to the PostCreated
event to perform custom processing:
use TomatoPHP\FilamentCms\Events\PostCreated; use Illuminate\Support\Facades\Event; Event::listen(PostCreated::class, function ($event) { $post = $event->model; // Custom processing here if ($post->type === 'open-source') { // Do something with imported repository } });
Custom Notification Handling
use Illuminate\Support\Facades\Notification; use TomatoPHP\FilamentCmsGithub\Jobs\GitHubMetaGetterJob; class CustomNotificationHandler { public function handle(GitHubMetaGetterJob $job) { // Custom notification logic } }
Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
Development Setup
# Clone the repository git clone https://github.com/tomatophp/filament-cms-github.git # Install dependencies composer install # Run tests composer test
Testing
if you like to run PEST
testing just use this command
composer test
Code Style
if you like to fix the code style, just use this command
composer format
PHPStan
if you like to check the code by PHPStan
just use this command
composer analyse
Other Filament Packages
Check out our Awesome TomatoPHP