From 03eb7fc50a6f49234bf7b5a84eac750c649784fe Mon Sep 17 00:00:00 2001 From: Marc Hagen Date: Mon, 12 Feb 2024 16:18:29 +0100 Subject: [PATCH] Some GitHub users dont have there email exposed. In this case use username and username+example.com --- src/Integrations/Github/GitHubIntegration.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Integrations/Github/GitHubIntegration.php b/src/Integrations/Github/GitHubIntegration.php index 1a7cf47c..dbc1d976 100644 --- a/src/Integrations/Github/GitHubIntegration.php +++ b/src/Integrations/Github/GitHubIntegration.php @@ -432,7 +432,7 @@ public function fetchUser(Request|array $requestOrToken, array $options = [], ar $response = $response->toArray(); $response['user_name'] = $response['login'] ?? null; - $response['user_identifier'] = $response['email']; + $response['user_identifier'] = $response['email'] ?? $response['login']; $response['external_id'] = isset($response['id']) ? $this->getConfig()->getName() . ':' . $response['id'] : null; return $response; @@ -520,10 +520,12 @@ protected function getApiHeaders(array $token, array $default = []): array */ public function createUser(array $userData): User { + $email = $userData['email'] ?? (str_contains($userData['user_identifier'], '@') ? $userData['user_identifier'] : $userData['user_identifier'] .'@example.com'); + $user = new User(); $user->setEnabled(true) ->setRoles($this->getConfig()->roles()) - ->setEmail($userData['email']) + ->setEmail($email) ->setUsername($userData['login']) ->setGithubId($userData['external_id'] ?? null) ->generateApiToken();