<commit_before>require 'problem_child'
require 'securerandom'
require 'json'

Dotenv.load

module CommentCard
  class App < Sinatra::Base

    include ProblemChild::Helpers

    configure do
      use Rack::Session::Dalli, cache: ProblemChild::Memcache.client
    end

    set :github_options, {
      :scopes => "public_repo,read:org"
    }

    ENV['WARDEN_GITHUB_VERIFIER_SECRET'] ||= SecureRandom.hex
    register Sinatra::Auth::Github

    enable :sessions
    use Rack::Session::Cookie, {
      :http_only => true,
      :secret => ENV['SESSION_SECRET'] || SecureRandom.hex
    }

    configure :production do
      require 'rack-ssl-enforcer'
      use Rack::SslEnforcer
    end

    def render_template(template, locals)
      halt erb template, :layout => :layout, :locals => locals.merge({ :template => template })
    end

    get '/:owner/:repo/issues/new' do
      if form_data["title"]  #post oauth redirect back to GET route, submit commment
        repo = "#{form_data["owner"]}/#{form_data["repo"]}"
        session["form_data"] = form_data.reject { |k,v| ["owner", "repo"].include?(k) }.to_json
        issue = client.create_issue(repo,form_data["title"],issue_body)
        session[:form_data] = nil
        render_template :confirmation, {
          :owner => params[:owner],
          :repo  => params[:repo],
          :issue => issue
        }
      else
        render_template :new, {
          :owner                     => params['owner'],
          :repo                      => params["repo"],
          :guest_submissions_enabled => anonymous_submissions?,
          :title                     => params["title"],
          :body                      => params["body"],
          :name                      => params["name"]
        }
      end
    end

    post '/:owner/:repo/issues/new' do
      session[:form_data] = params.reject { |k,v| ["type", "captures"].include?(k) }.to_json<commit_msg>use render_template from problem child<commit_after>require 'problem_child'
require 'securerandom'
require 'json'

Dotenv.load

module CommentCard
  class App < Sinatra::Base

    include ProblemChild::Helpers

    configure do
      use Rack::Session::Dalli, cache: ProblemChild::Memcache.client
    end

    set :github_options, {
      :scopes => "public_repo,read:org"
    }

    ENV['WARDEN_GITHUB_VERIFIER_SECRET'] ||= SecureRandom.hex
    register Sinatra::Auth::Github

    enable :sessions
    use Rack::Session::Cookie, {
      :http_only => true,
      :secret => ENV['SESSION_SECRET'] || SecureRandom.hex
    }

    configure :production do
      require 'rack-ssl-enforcer'
      use Rack::SslEnforcer
    end

    get '/:owner/:repo/issues/new' do
      if form_data["title"]  #post oauth redirect back to GET route, submit commment
        repo = "#{form_data["owner"]}/#{form_data["repo"]}"
        session["form_data"] = form_data.reject { |k,v| ["owner", "repo"].include?(k) }.to_json
        issue = client.create_issue(repo,form_data["title"],issue_body)
        session[:form_data] = nil
        render_template :confirmation, {
          :owner => params[:owner],
          :repo  => params[:repo],
          :issue => issue
        }
      else
        render_template :new, {
          :owner                     => params['owner'],
          :repo                      => params["repo"],
          :guest_submissions_enabled => anonymous_submissions?,
          :title                     => params["title"],
          :body                      => params["body"],
          :name                      => params["name"]
        }
      end
    end

    post '/:owner/:repo/issues/new' do
      session[:form_data] = params.reject { |k,v| ["type", "captures"].include?(k) }.to_json
{'fraction_non_alphanumeric': 0.13612004287245444, 'fraction_numerical': 0.0, 'mean_word_length': 2.2918871252204585, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, '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': '6764821', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1098, 'n_words': 228}