<commit_before>require 'octokit'
require 'userinput'

##
# Define Auth object and related info for Octoauth
module Octoauth
  ##
  # Default OAuth scopes for tokens
  DEFAULT_SCOPES = []

  ##
  # Prompt information for collecting user info
  PROMPTS = {
    login: UserInput.new(message: 'GitHub username', validation: /\w+/),
    password: UserInput.new(message: 'Password', secret: true),
    twofactor: UserInput.new(message: '2FA token', validation: /\d+/)
  }

  ##
  # Authentication object
  class Auth
    attr_reader :token

    def initialize(params = {})
      params[:config_note] = params[:note].dup
      if params.include? :api_endpoint
        params[:config_note] << "--#{params[:api_endpoint]}"
      end
      @config = ConfigFile.new file: params[:file], note: params[:config_note]
      @token = load_token params
    end

    def save
      fail 'No token to save' unless @token
      @config.token = @token
      @config.write
    end

    private

    def load_token(params = {})
      return @config.token if @config.token
      params[:login] ||= PROMPTS[:login].ask
      params[:password] ||= PROMPTS[:password].ask
      params[:twofactor] ||= PROMPTS[:twofactor].ask if params[:needs2fa]
      params[:scopes] ||= DEFAULT_SCOPES
      if params[:twofactor]
        params[:headers] = { 'X-GitHub-OTP' => params[:twofactor] }
      end
      authenticate! params
    end<commit_msg>fix nil dup error<commit_after>require 'octokit'
require 'userinput'

##
# Define Auth object and related info for Octoauth
module Octoauth
  ##
  # Default OAuth scopes for tokens
  DEFAULT_SCOPES = []

  ##
  # Prompt information for collecting user info
  PROMPTS = {
    login: UserInput.new(message: 'GitHub username', validation: /\w+/),
    password: UserInput.new(message: 'Password', secret: true),
    twofactor: UserInput.new(message: '2FA token', validation: /\d+/)
  }

  ##
  # Authentication object
  class Auth
    attr_reader :token

    def initialize(params = {})
      params[:config_note] = "#{params[:note]}"
      if params.include? :api_endpoint
        params[:config_note] << "--#{params[:api_endpoint]}"
      end
      @config = ConfigFile.new file: params[:file], note: params[:config_note]
      @token = load_token params
    end

    def save
      fail 'No token to save' unless @token
      @config.token = @token
      @config.write
    end

    private

    def load_token(params = {})
      return @config.token if @config.token
      params[:login] ||= PROMPTS[:login].ask
      params[:password] ||= PROMPTS[:password].ask
      params[:twofactor] ||= PROMPTS[:twofactor].ask if params[:needs2fa]
      params[:scopes] ||= DEFAULT_SCOPES
      if params[:twofactor]
        params[:headers] = { 'X-GitHub-OTP' => params[:twofactor] }
      end
      authenticate! params
    end
{'fraction_non_alphanumeric': 0.13149522799575822, 'fraction_numerical': 0.0014139271827500884, 'mean_word_length': 3.0955137481910273, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3583827', 'n_tokens_mistral': 892, 'n_tokens_neox': 873, 'n_words': 220}