<commit_before>require 'sinatra'
require 'sinatra/auth/github'
require './lib/view_helpers'
require 'rack/ssl-enforcer'
require 'dweet'
require 'pry' if AppEnv.development?

module JekyllPizza
  class App < Sinatra::Base
    use Rack::SslEnforcer if AppEnv.production?
    set :session_secret, ENV['RACK_SESSION_SECRET']
    use Rack::Session::Cookie, key: '_jekyllpizza_session',
                               path: '/',
                               expire_after: 2_592_000, # In seconds
                               secret: settings.session_secret
    include ViewHelpers
    set :github_options,       scopes: 'public_repo',
                               secret: ENV['GITHUB_CLIENT_SECRET'],
                               client_id: ENV['GITHUB_CLIENT_ID']

    register Sinatra::Auth::Github

    get '/' do
      @flash ||= []
      slim :index, layout: :default
    end

    get '/new' do
      # TODO: improve flash messaging
      @flash ||= []
      @flash << params[:error] if params[:error]
      authenticate!
      setup_user
      dweet_login

      slim :new, layout: :default
    end

    post '/create' do
      @flash ||= []
      authenticate!
      setup_user
      @failures ||= 0

      begin
        # TODO: improve validations
        if @api.repository?(user_repo_path(site_params))
          @failures += 1
          redirect "/new?error=Oops, that repository already exists, pick a new path!&failures=#{@failures}"
        end

        @repo = create_jekyll_repo(site_params)
        @site_url = full_repo_url(site_params)
        check_build_status
        dweet_creation
        slim :create, layout: :default
      rescue StandardError => e
        # TODO: improve logging, error handling.. issue #
        puts e.message<commit_msg>Hot fix - dweet error "no implicit conversion of Fixnum into String "<commit_after>require 'sinatra'
require 'sinatra/auth/github'
require './lib/view_helpers'
require 'rack/ssl-enforcer'
require 'dweet'
require 'pry' if AppEnv.development?

module JekyllPizza
  class App < Sinatra::Base
    use Rack::SslEnforcer if AppEnv.production?
    set :session_secret, ENV['RACK_SESSION_SECRET']
    use Rack::Session::Cookie, key: '_jekyllpizza_session',
                               path: '/',
                               expire_after: 2_592_000, # In seconds
                               secret: settings.session_secret
    include ViewHelpers
    set :github_options,       scopes: 'public_repo',
                               secret: ENV['GITHUB_CLIENT_SECRET'],
                               client_id: ENV['GITHUB_CLIENT_ID']

    register Sinatra::Auth::Github

    get '/' do
      @flash ||= []
      slim :index, layout: :default
    end

    get '/new' do
      # TODO: improve flash messaging
      @flash ||= []
      @flash << params[:error] if params[:error]
      authenticate!
      setup_user
      dweet_login

      slim :new, layout: :default
    end

    post '/create' do
      @flash ||= []
      authenticate!
      setup_user
      @failures ||= 0

      begin
        # TODO: improve validations
        if @api.repository?(user_repo_path(site_params))
          @failures += 1
          redirect "/new?error=Oops, that repository already exists, pick a new path!&failures=#{@failures}"
        end

        @repo = create_jekyll_repo(site_params)
        @site_url = full_repo_url(site_params)
        check_build_status
        # dweet_creation
        slim :create, layout: :default
      rescue StandardError => e
        # TODO: improve logging, error handling.. issue #
        puts e.message
{'fraction_non_alphanumeric': 0.09894385769872151, 'fraction_numerical': 0.005002779321845469, 'mean_word_length': 2.1268462206776717, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6895804', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1057, 'n_words': 260}