<commit_before>require_relative 'helpers/pagination'
require_relative 'helpers/authentication'

require 'octokit'
require 'omniauth'
require 'omniauth-github'
require 'rdiscount'
require 'sinatra/base'

module Kobol
  class App < Sinatra::Base
    use Rack::Session::Cookie, :key => 'rack.session',
                               :domain => 'pacific-spire-2274.herokuapp.com',
                               :path => '/',
                               :expire_after => 2592000,
                               :secret => ENV['KOBOL_SECRET']

    use OmniAuth::Builder do
      provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
    end

    helpers Kobol::Helpers::Pagination
    helpers Kobol::Helpers::Authentication

    enable :sessions
    set :session_secret, ENV["KOBOL_SECRET"]

    set :public_folder, APP_ROOT + '/public'
    set :views, APP_ROOT + "/views"

    get '/' do
      @nickname = session[:nickname] if current_user
      retrieve_issues(page)

      erb :issues
    end

    get '/label-guide' do
      erb :label_guide
    end

    %w(get post).each do |method|
      send(method, "/auth/:provider/callback") do
        session[:token] = env['omniauth.auth']['credentials']['token']
        session[:uid] = env['omniauth.auth']['uid']
        session[:nickname] = env['omniauth.auth']['info']['nickname']
        redirect "/"
      end
    end

    get '/auth/failure' do
      redirect '/'
    end

    get '/logout' do
      session.clear
      redirect "/"
    end

    def retrieve_issues page=1
      issues_request.search(parameters(params), page)

      @total = issues_request.total
      @issues = issues_request.issues
    rescue Octokit::TooManyRequests => e
      @issues = []
      @message =  "We have a very limited amount of requests available. Login with github to take advantage of authenticated request limit."
    rescue Exception => e
      @issues = []
      @message =  "Something went wrong :(."
    end

    protected

    def issues_request
      login_params = current_user ? { login: session[:nickname], access_token: session[:token] } : nil
      @issues_request ||= Kobol::Requests::Issues.new(login_params)
    end

    def parameters(hash={}, properties)
      Kobol::Requests::Issues::PERMITTED.each do |key|
        hash[key] = []
        properties[key.to_s].split(",").each {|value| hash[key] << value } rescue ""
      end
      hash
    end
  end
end<commit_msg>display exception error<commit_after>require_relative 'helpers/pagination'
require_relative 'helpers/authentication'

require 'octokit'
require 'omniauth'
require 'omniauth-github'
require 'rdiscount'
require 'sinatra/base'

module Kobol
  class App < Sinatra::Base
    use Rack::Session::Cookie, :key => 'rack.session',
                               :domain => 'pacific-spire-2274.herokuapp.com',
                               :path => '/',
                               :expire_after => 2592000,
                               :secret => ENV['KOBOL_SECRET']

    use OmniAuth::Builder do
      provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
    end

    helpers Kobol::Helpers::Pagination
    helpers Kobol::Helpers::Authentication

    enable :sessions
    set :session_secret, ENV["KOBOL_SECRET"]

    set :public_folder, APP_ROOT + '/public'
    set :views, APP_ROOT + "/views"

    get '/' do
      @nickname = session[:nickname] if current_user
      retrieve_issues(page)

      erb :issues
    end

    get '/label-guide' do
      erb :label_guide
    end

    %w(get post).each do |method|
      send(method, "/auth/:provider/callback") do
        session[:token] = env['omniauth.auth']['credentials']['token']
        session[:uid] = env['omniauth.auth']['uid']
        session[:nickname] = env['omniauth.auth']['info']['nickname']
        redirect "/"
      end
    end

    get '/auth/failure' do
      redirect '/'
    end

    get '/logout' do
      session.clear
      redirect "/"
    end

    def retrieve_issues page=1
      issues_request.search(parameters(params), page)

      @total = issues_request.total
      @issues = issues_request.issues
    rescue Octokit::TooManyRequests => e
      @issues = []
      @message =  "We have a very limited amount of requests available. Login with github to take advantage of authenticated request limit."
    rescue Exception => e
      @issues = []
      @message =  e.message
    end

    protected

    def issues_request
      login_params = current_user ? { login: session[:nickname], access_token: session[:token] } : nil
      @issues_request ||= Kobol::Requests::Issues.new(login_params)
    end

    def parameters(hash={}, properties)
      Kobol::Requests::Issues::PERMITTED.each do |key|
        hash[key] = []
        properties[key.to_s].split(",").each {|value| hash[key] << value } rescue ""
      end
      hash
    end
  end
end
{'fraction_non_alphanumeric': 0.12445909746548527, 'fraction_numerical': 0.00494539460127756, 'mean_word_length': 2.532751091703057, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '5475881', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1459, 'n_words': 339}