<commit_before>class ScrapersController < ApplicationController
  before_filter :authenticate_user!, except: :show
  
  def new
    # Get the list of repositories
    # TODO Move this to an initializer
    Octokit.auto_paginate = true
    client = Octokit::Client.new :access_token => current_user.access_token
    @repos = client.repositories
    puts @repos.first.to_yaml
    @scraper = Scraper.new
  end

  def create
    # Get the rest of the info from the API
    client = Octokit::Client.new :access_token => current_user.access_token

    # Look up the repository by name
    repo = client.repository("#{current_user.to_param}/#{params[:scraper][:name]}")

    # Populate a new scraper with information from the repo
    @scraper = Scraper.new(name: repo.name, full_name: repo.full_name,
      description: repo.description, github_id: repo.id, owner_id: current_user.id,
      github_url: repo.rels[:html].href, git_url: repo.rels[:git].href)
    if @scraper.save
      redirect_to @scraper
    else
      render :new<commit_msg>Sort repos by date they were last pushed to (matches github). Fixes #57<commit_after>class ScrapersController < ApplicationController
  before_filter :authenticate_user!, except: :show
  
  def new
    # Get the list of repositories
    # TODO Move this to an initializer
    Octokit.auto_paginate = true
    client = Octokit::Client.new :access_token => current_user.access_token
    @repos = client.repositories(nil, sort: :pushed)
    @scraper = Scraper.new
  end

  def create
    # Get the rest of the info from the API
    client = Octokit::Client.new :access_token => current_user.access_token

    # Look up the repository by name
    repo = client.repository("#{current_user.to_param}/#{params[:scraper][:name]}")

    # Populate a new scraper with information from the repo
    @scraper = Scraper.new(name: repo.name, full_name: repo.full_name,
      description: repo.description, github_id: repo.id, owner_id: current_user.id,
      github_url: repo.rels[:html].href, git_url: repo.rels[:git].href)
    if @scraper.save
      redirect_to @scraper
    else
      render :new
{'fraction_non_alphanumeric': 0.09519321394910461, 'fraction_numerical': 0.000942507068803016, 'mean_word_length': 3.6969026548672566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5613606', 'n_tokens_mistral': 689, 'n_tokens_neox': 661, 'n_words': 185}