getId(); $profile = GitHubProfile::fromSocialite($githubUser); $email = mb_trim((string) $githubUser->getEmail()); // Null when GitHub can't answer, which keeps the last known value. $hasSponsorsListing = $this->github->hasSponsorsListing($githubUser->token); return DB::transaction(function () use ($githubId, $profile, $email, $hasSponsorsListing): User { $this->updateStaleHandles->handle($profile->handle, $githubId); // A profile never changes type, so an organization's GitHub ID would fail here, but GitHub never signs one in... $id = Profile::query()->updateOrCreate([ 'github_id' => $githubId, 'type' => ProfileType::User, ], [ ...$profile->attributes(), 'github_synced_at' => now(), ])->id; DB::table('deleted_github_accounts')->where('github_id', $githubId)->delete(); $user = User::query()->updateOrCreate([ 'id' => $id, 'github_id' => $githubId, ], [ 'company' => $profile->company, 'email' => $email === '' ? null : $email, ...($hasSponsorsListing === null ? [] : ['has_sponsors_listing' => $hasSponsorsListing]), ]); if ($user->wasRecentlyCreated) { $this->createFollowsFromPendingFollows->handle($user); } return $user; }); } }