Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/Http/Controllers/Auth/GithubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions app/Social/GithubUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions lang/en/errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=":login">login</a> instead?',
];
11 changes: 11 additions & 0 deletions tests/Unit/Social/GithubUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
]);