diff --git a/app/Console/Commands/Command.php b/app/Console/Commands/Command.php new file mode 100644 index 0000000..2f5aae8 --- /dev/null +++ b/app/Console/Commands/Command.php @@ -0,0 +1,51 @@ +output->progressStart($query->count()); + $query->eachById(function (Model $value) use ($callback): void { + $callback($value); + $this->output->progressAdvance(); + }); + $this->output->progressFinish(); + + return; + } + + if (is_iterable($totalSteps)) { + $this->output->progressStart(count($totalSteps)); + LazyCollection::make($totalSteps)->each(function (mixed $value) use ($callback): void { + $callback($value); + $this->output->progressAdvance(); + }); + $this->output->progressFinish(); + + return; + } + + $this->output->progressStart($totalSteps); + + LazyCollection::range(1, $totalSteps)->each(function (int $value) use ($callback): void { + $callback($value); + $this->output->progressAdvance(); + }); + + $this->output->progressFinish(); + } +} diff --git a/app/Console/Commands/GithubOrganizationDetails.php b/app/Console/Commands/GithubOrganizationDetails.php index be78d08..f5ac059 100644 --- a/app/Console/Commands/GithubOrganizationDetails.php +++ b/app/Console/Commands/GithubOrganizationDetails.php @@ -4,7 +4,6 @@ use App\Jobs\UpdateOrganizationDetails; use App\Models\Organization; -use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; class GithubOrganizationDetails extends Command @@ -15,14 +14,15 @@ class GithubOrganizationDetails extends Command public function handle(): void { - Organization::query() + $query = Organization::query() ->whereHas('members', fn (Builder $query) => $query->whereIsRegistered()) ->when( $this->argument('name'), fn (Builder $query, string $name) => $query->where('name', $name) - ) - ->each(static function (Organization $organization): void { - UpdateOrganizationDetails::dispatch($organization); - }); + ); + + $this->withProgressBar($query, static function (Organization $organization): void { + UpdateOrganizationDetails::dispatch($organization); + }); } } diff --git a/app/Console/Commands/GithubOrganizationRepositories.php b/app/Console/Commands/GithubOrganizationRepositories.php index 15d2b81..0d74fe4 100644 --- a/app/Console/Commands/GithubOrganizationRepositories.php +++ b/app/Console/Commands/GithubOrganizationRepositories.php @@ -4,7 +4,6 @@ use App\Jobs\LoadOrganizationRepositories; use App\Models\Organization; -use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; class GithubOrganizationRepositories extends Command @@ -15,14 +14,15 @@ class GithubOrganizationRepositories extends Command public function handle(): void { - Organization::query() + $query = Organization::query() ->whereHas('members', fn (Builder $query) => $query->whereIsRegistered()) ->when( $this->argument('name'), fn (Builder $query, string $name) => $query->where('name', $name) - ) - ->each(static function (Organization $organization): void { - LoadOrganizationRepositories::dispatch($organization); - }); + ); + + $this->withProgressBar($query, static function (Organization $organization): void { + LoadOrganizationRepositories::dispatch($organization); + }); } } diff --git a/app/Console/Commands/GithubRepositoryDetails.php b/app/Console/Commands/GithubRepositoryDetails.php index 38f862d..ca95b22 100644 --- a/app/Console/Commands/GithubRepositoryDetails.php +++ b/app/Console/Commands/GithubRepositoryDetails.php @@ -6,7 +6,6 @@ use App\Models\Organization; use App\Models\Repository; use App\Models\User; -use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; class GithubRepositoryDetails extends Command @@ -17,21 +16,23 @@ class GithubRepositoryDetails extends Command public function handle(): void { - Repository::query() + $query = Repository::query() ->when( $this->argument('name'), fn (Builder $query, string $name) => $query->where('name', $name) ) - ->with('owner') - ->get() - ->reject(function (Repository $repository): bool { - return $repository->owner instanceof User && $repository->owner->github_access_token === null; - }) - ->reject(function (Repository $repository): bool { - return $repository->owner instanceof Organization && $repository->owner->members()->whereIsRegistered()->doesntExist(); - }) - ->each(static function (Repository $repository): void { - UpdateRepositoryDetails::dispatch($repository); - }); + ->with('owner'); + + $this->withProgressBar($query, static function (Repository $repository): void { + if ($repository->owner instanceof User && $repository->owner->github_access_token === null) { + return; + } + + if ($repository->owner instanceof Organization && $repository->owner->members()->whereIsRegistered()->doesntExist()) { + return; + } + + UpdateRepositoryDetails::dispatch($repository); + }); } } diff --git a/app/Console/Commands/GithubUserContributions.php b/app/Console/Commands/GithubUserContributions.php index e597332..4669e91 100644 --- a/app/Console/Commands/GithubUserContributions.php +++ b/app/Console/Commands/GithubUserContributions.php @@ -4,7 +4,6 @@ use App\Jobs\SyncUserContributions; use App\Models\User; -use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; class GithubUserContributions extends Command @@ -15,14 +14,15 @@ class GithubUserContributions extends Command public function handle(): void { - User::query() + $query = User::query() ->whereIsRegistered() ->when( $this->argument('name'), fn (Builder $query, string $name) => $query->where('name', $name) - ) - ->each(static function (User $user): void { - SyncUserContributions::dispatch($user); - }); + ); + + $this->withProgressBar($query, static function (User $user): void { + SyncUserContributions::dispatch($user); + }); } } diff --git a/app/Console/Commands/GithubUserDetails.php b/app/Console/Commands/GithubUserDetails.php index 0519652..f228996 100644 --- a/app/Console/Commands/GithubUserDetails.php +++ b/app/Console/Commands/GithubUserDetails.php @@ -4,7 +4,6 @@ use App\Jobs\UpdateUserDetails; use App\Models\User; -use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; class GithubUserDetails extends Command @@ -15,14 +14,15 @@ class GithubUserDetails extends Command public function handle(): void { - User::query() + $query = User::query() ->whereIsRegistered() ->when( $this->argument('name'), fn (Builder $query, string $name) => $query->where('name', $name) - ) - ->each(static function (User $user): void { - UpdateUserDetails::dispatch($user); - }); + ); + + $this->withProgressBar($query, static function (User $user): void { + UpdateUserDetails::dispatch($user); + }); } } diff --git a/app/Console/Commands/GithubUserOrganizations.php b/app/Console/Commands/GithubUserOrganizations.php index e86ff10..0be2a79 100644 --- a/app/Console/Commands/GithubUserOrganizations.php +++ b/app/Console/Commands/GithubUserOrganizations.php @@ -4,7 +4,6 @@ use App\Jobs\SyncUserOrganizations; use App\Models\User; -use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; class GithubUserOrganizations extends Command @@ -15,14 +14,15 @@ class GithubUserOrganizations extends Command public function handle(): void { - User::query() + $query = User::query() ->whereIsRegistered() ->when( $this->argument('name'), fn (Builder $query, string $name) => $query->where('name', $name) - ) - ->each(static function (User $user): void { - SyncUserOrganizations::dispatch($user); - }); + ); + + $this->withProgressBar($query, static function (User $user): void { + SyncUserOrganizations::dispatch($user); + }); } } diff --git a/app/Console/Commands/GithubUserRepositories.php b/app/Console/Commands/GithubUserRepositories.php index 4d502f1..f9151b0 100644 --- a/app/Console/Commands/GithubUserRepositories.php +++ b/app/Console/Commands/GithubUserRepositories.php @@ -4,7 +4,6 @@ use App\Jobs\LoadUserRepositories; use App\Models\User; -use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; class GithubUserRepositories extends Command @@ -15,14 +14,15 @@ class GithubUserRepositories extends Command public function handle(): void { - User::query() + $query = User::query() ->whereIsRegistered() ->when( $this->argument('name'), fn (Builder $query, string $name) => $query->where('name', $name) - ) - ->each(static function (User $use): void { - LoadUserRepositories::dispatch($use); - }); + ); + + $this->withProgressBar($query, static function (User $use): void { + LoadUserRepositories::dispatch($use); + }); } }