|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Console\Commands; |
| 4 | + |
| 5 | +use App\Models\FrozenRepository; |
| 6 | +use App\Models\GithubApi; |
| 7 | +use Illuminate\Console\Command; |
| 8 | +use Illuminate\Support\Carbon; |
| 9 | + |
| 10 | +class FroozeRepositories extends Command { |
| 11 | + /** |
| 12 | + * The name and signature of the console command. |
| 13 | + * |
| 14 | + * @var string |
| 15 | + */ |
| 16 | + protected $signature = 'app:frooze-repositories'; |
| 17 | + |
| 18 | + /** |
| 19 | + * The console command description. |
| 20 | + * |
| 21 | + * @var string |
| 22 | + */ |
| 23 | + protected $description = 'Load and frooze oldest and starred repositories'; |
| 24 | + |
| 25 | + /** |
| 26 | + * Execute the console command. |
| 27 | + */ |
| 28 | + public function handle() { |
| 29 | + $client = new GithubApi(); |
| 30 | + $repositories = $client->getOldestStarredRepositories(); |
| 31 | + |
| 32 | + FrozenRepository::truncate(); |
| 33 | + |
| 34 | + FrozenRepository::insert( |
| 35 | + array_map( |
| 36 | + function ($rep) { |
| 37 | + return array( |
| 38 | + 'created_at' => Carbon::now(), |
| 39 | + 'name' => $rep->name, |
| 40 | + 'githubId' => $rep->id, |
| 41 | + 'fullName' => $rep->fullName, |
| 42 | + 'description' => $rep->description, |
| 43 | + 'url' => $rep->url, |
| 44 | + 'githubCreatedAt' => $rep->createdAt, |
| 45 | + 'githubUpdatedAt' => $rep->updatedAt, |
| 46 | + 'language' => $rep->language, |
| 47 | + 'topics' => json_encode($rep->topics), |
| 48 | + 'watchers' => $rep->watchers, |
| 49 | + 'forks' => $rep->forks, |
| 50 | + 'stars' => $rep->stars, |
| 51 | + 'ownerIsOrganization' => $rep->ownerIsOrganization, |
| 52 | + 'ownerLogin' => $rep->owner->login, |
| 53 | + 'ownerGithubId' => $rep->owner->id, |
| 54 | + 'ownerAvatarUrl' => $rep->owner->avatarUrl, |
| 55 | + 'year' => $rep->createdAt->format('Y'), |
| 56 | + ); |
| 57 | + }, $repositories) |
| 58 | + ); |
| 59 | + } |
| 60 | +} |
0 commit comments