mirror of
https://github.com/phpmon/website
synced 2025-08-07 06:40:08 +02:00
Retrieve total stars and downloads
This commit is contained in:
46
app/Console/Commands/RetrieveGitHubData.php
Normal file
46
app/Console/Commands/RetrieveGitHubData.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class RetrieveGitHubData extends Command
|
||||
{
|
||||
protected $signature = 'github:fetch';
|
||||
|
||||
protected $description = 'Fetches GitHub repository data (and stars + downloads)';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$repositoryResponse = Http::get('https://api.github.com/repos/nicoverbruggen/phpmon');
|
||||
$releasesResponse = Http::get('https://api.github.com/repos/nicoverbruggen/phpmon/releases');
|
||||
|
||||
if ($repositoryResponse->failed()) {
|
||||
Log::error($repositoryResponse->body());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($releasesResponse->failed()) {
|
||||
Log::error($releasesResponse->body());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$data = json_decode($repositoryResponse->body(), null, 512, JSON_THROW_ON_ERROR);
|
||||
$releases = json_decode($releasesResponse->body(), null, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
Cache::put('stargazers', $data->stargazers_count);
|
||||
Cache::put('downloads', $total = collect($releases)
|
||||
->where('prerelease', false)
|
||||
->sum(fn ($release) => collect($release->assets)
|
||||
->sum('download_count')));
|
||||
|
||||
$this->info("PHP Monitor currently has {$data->stargazers_count} stargazers and {$total} total downloads.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -7,26 +7,13 @@
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
$schedule->command('github:fetch')->everySixHours();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
// require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user