<commit_before>class User < ActiveRecord::Base
  has_many :user_repos
  has_many :repos, through: :user_repos

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :omniauthable, :omniauth_providers => [:github]
   		#:database_authenticatable, :registerable,
        #:recoverable, :rememberable, :trackable, :validatable, 

  def self.find_for_github_oauth(auth)
  	where(:email => auth["info"]["email"]).first_or_create do |user|
  		user.provider = auth.provider
  		user.token = auth.credentials.token
      user.email = auth.info.email
      user.name = auth.info.name
      user.github_login = auth.extra.raw_info.login
      user.image = auth.info.image
  	end
  end

  def organization_repos(client)
    Octokit.auto_paginate = true
    organizations = client.organizations.map { |orgs| orgs.login }
    org_repos = organizations.map do |org|
      client.org_repositories(org)
    end.flatten
  end

  def github_repos
    Octokit.per_page = 100
    client = Octokit::Client.new(:access_token => self.token)
    repos_count = client.search_repositories("user:#{client.user[:login]}").total_count
    last_response = client.last_response
    number_of_pages = last_response.rels[:last].href.match(/page=(\d+)$/)[1]
    repos = []
    (1..number_of_pages.to_i).each do |page|
      repos += client.search_repositories("user:#{client.user[:login]}", :sort => "updated", :order => "desc", :page => page)[:items]
    end
    org_repos = organization_repos(client)
    org_repos.each do |repo|
      repos << repo
    end
    return {:repos => repos}
  end

  def add_from_collaborators
    user_repos_urls = self.repos.map do |repo|
      repo.address
    end
    repos_return = self.github_repos
    repos = repos_return[:repos].reject { |repo|
      user_repos_urls.include?(repo.html_url)
    }
    repos.each do |repo|
      if new_user_repo = Repo.where(address: repo.html_url).first
        self.repos << new_user_repo
      end
    end
  end
end<commit_msg>auto-paginate to return all organization and private repos<commit_after>class User < ActiveRecord::Base
  has_many :user_repos
  has_many :repos, through: :user_repos

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :omniauthable, :omniauth_providers => [:github]
   		#:database_authenticatable, :registerable,
        #:recoverable, :rememberable, :trackable, :validatable, 

  def self.find_for_github_oauth(auth)
  	where(:email => auth["info"]["email"]).first_or_create do |user|
  		user.provider = auth.provider
  		user.token = auth.credentials.token
      user.email = auth.info.email
      user.name = auth.info.name
      user.github_login = auth.extra.raw_info.login
      user.image = auth.info.image
  	end
  end

  def organization_repos(client)
    Octokit.auto_paginate = true
    organizations = client.organizations.map { |orgs| orgs.login }
    org_repos = organizations.map do |org|
      client.org_repositories(org)
    end.flatten
  end

  def github_repos
    Octokit.auto_paginate = true
    client = Octokit::Client.new(:access_token => self.token)
    repos = client.search_repositories("user:#{client.user[:login]}")[:items]
    org_repos = organization_repos(client)
    repos << org_repos
    repos.flatten!
    repos.uniq! { |repo| repo.id }
    return {:repos => repos}
  end

  def add_from_collaborators
    user_repos_urls = self.repos.map do |repo|
      repo.address
    end
    repos_return = self.github_repos
    repos = repos_return[:repos].reject { |repo|
      user_repos_urls.include?(repo.html_url)
    }
    repos.each do |repo|
      if new_user_repo = Repo.where(address: repo.html_url).first
        self.repos << new_user_repo
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11406943356825894, 'fraction_numerical': 0.0013051422605063951, 'mean_word_length': 3.4766355140186915, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, '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': '3991805', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1252, 'n_words': 251}