<commit_before>class GoogleUser < ApplicationRecord
  belongs_to :user

  include AvatarSource

  def self.from_auth(auth, current_user)
    google_user = GoogleUser.find_or_initialize_by(google_id: auth.uid)
    google_user.user = [
      current_user,
      google_user.user,
      User.joins(:twitch).find_by(twitch_users: {email: auth.info.email}),
      User.new(name: auth.info.email.split('@')[0])
    ].compact.first

    unless google_user.user.save
      google_user.user.errors.full_messages.each do |error|
        google_user.errors.add(:user, error)
      end
      return google_user
    end

    google_user.assign_attributes(
      access_token:            auth.credentials.token,
      access_token_expires_at: Time.at(auth.credentials.expires_at).to_datetime,
      name:                    auth.info.name,
      first_name:              auth.info.first_name,
      last_name:               auth.info.last_name,
      email:                   auth.info.email,
      avatar:                  auth.info.image,
      url:                     auth.info.urls.google
    )

    google_user.save<commit_msg>Fix Google accounts with periods breaking signin<commit_after>class GoogleUser < ApplicationRecord
  belongs_to :user

  include AvatarSource

  def self.from_auth(auth, current_user)
    google_user = GoogleUser.find_or_initialize_by(google_id: auth.uid)
    google_user.user = [
      current_user,
      google_user.user,
      User.joins(:twitch).find_by(twitch_users: {email: auth.info.email}),
      User.new(name: auth.info.email.split('@')[0].remove('.'))
    ].compact.first

    unless google_user.user.save
      google_user.user.errors.full_messages.each do |error|
        google_user.errors.add(:user, error)
      end
      return google_user
    end

    google_user.assign_attributes(
      access_token:            auth.credentials.token,
      access_token_expires_at: Time.at(auth.credentials.expires_at).to_datetime,
      name:                    auth.info.name,
      first_name:              auth.info.first_name,
      last_name:               auth.info.last_name,
      email:                   auth.info.email,
      avatar:                  auth.info.image,
      url:                     auth.info.urls.google
    )

    google_user.save
{'fraction_non_alphanumeric': 0.09540481400437636, 'fraction_numerical': 0.00087527352297593, 'mean_word_length': 2.2061711079943898, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1846124', 'n_tokens_mistral': 710, 'n_tokens_neox': 693, 'n_words': 107}