diff --git a/app/Http/Controllers/Auth/GithubController.php b/app/Http/Controllers/Auth/GithubController.php index c170f17ee..c4abc1ea3 100644 --- a/app/Http/Controllers/Auth/GithubController.php +++ b/app/Http/Controllers/Auth/GithubController.php @@ -67,6 +67,12 @@ private function userNotFound(GithubUser $user): RedirectResponse return redirect()->route('home'); } + if (! $user->hasPublicRepositories()) { + $this->error('errors.github_account_no_repositories'); + + return redirect()->route('home'); + } + return $this->redirectUserToRegistrationPage($user); } diff --git a/app/Social/GithubUser.php b/app/Social/GithubUser.php index 63e8203ed..15ac9d15c 100644 --- a/app/Social/GithubUser.php +++ b/app/Social/GithubUser.php @@ -13,6 +13,11 @@ public function __construct( ) { } + public function hasPublicRepositories(): bool + { + return $this->get('public_repos') > 0; + } + public function isTooYoung(): bool { return $this->createdAt() > $this->twoWeeksAgo(); diff --git a/lang/en/errors.php b/lang/en/errors.php index 55c8844e8..8f3f31cc0 100644 --- a/lang/en/errors.php +++ b/lang/en/errors.php @@ -5,5 +5,6 @@ 'fields' => 'Something went wrong. Please review the fields below.', 'github_invalid_state' => 'The request timed out. Please try again.', 'github_account_too_young' => 'Your Github account needs to be older than 2 weeks in order to register.', + 'github_account_no_repositories' => 'Your Github account needs to have at least 1 public repository in order to register.', 'github_account_exists' => 'We already found a user with the given GitHub account (:username). Would you like to login instead?', ]; diff --git a/tests/Unit/Social/GithubUserTest.php b/tests/Unit/Social/GithubUserTest.php index 939175927..191423297 100644 --- a/tests/Unit/Social/GithubUserTest.php +++ b/tests/Unit/Social/GithubUserTest.php @@ -14,3 +14,14 @@ expect($user->isTooYoung())->toBeTrue(); }); + +it('can determine if the user has public repositories', function (int $numberOfRepos, bool $expected) { + $user = new GithubUser(['public_repos' => $numberOfRepos]); + + expect($user->hasPublicRepositories())->toBe($expected); +})->with([ + [0, false], + [1, true], + [2, true], + [3, true], +]);