<commit_before>class ViewerController < ApplicationController
  def show_project
    @project_details = ProjectDetails.new(params)
    if @project_details.exists?
      render layout: nil
    else
      attempt_project_import_and_redirect
    end
  end

  def random
    project = Project.where("rubocop_offenses_count > 0").order("RANDOM()").first
    redirect_to(action: "show_project", username: project.username, name: project.name)
  end

  def project_not_found
  end

  private

  def attempt_project_import_and_redirect
    gh = GithubProject.new(name: @project_details.name, username: @project_details.username)
    if gh.exists?
      gh.to_project.save!
      redirect_to({action: :show_project}, {
        username: @project_details.username,
        name: @project_details.name,
      })
    else
      redirect_to action: "project_not_found", :flash => {
        :error => "Could not find that project '#{@project_details.full_name}'"
      }
    end
  end
end
<commit_msg>Show error when project contains no ruby code<commit_after>class ViewerController < ApplicationController
  def show_project
    @project_details = ProjectDetails.new(params)
    if @project_details.exists?
      render layout: nil
    else
      attempt_project_import_and_redirect
    end
  end

  def random
    project = Project.where("rubocop_offenses_count > 0").order("RANDOM()").first
    redirect_to(action: "show_project", username: project.username, name: project.name)
  end

  def project_not_found
  end

  private

  def attempt_project_import_and_redirect
    gh = GithubProject.new(name: @project_details.name, username: @project_details.username)
    if !gh.exists?
      redirect_to action: "project_not_found", flash: { error: "Could not find that project '#{@project_details.full_name}'" }
      return
    end
    if !gh.contains_ruby?
      redirect_to root_path, flash: { error: "This project does not seem to contain a significant amount of ruby code." }
      return
    end
    save_and_redirect_to_project gh.to_project
  end

  def save_and_redirect_to_project(project)
    project.save!
    redirect_to({action: :show_project}, {
      username: project.username,
      name: project.name,
    })
  end
end

{'fraction_non_alphanumeric': 0.08723021582733813, 'fraction_numerical': 0.0008992805755395684, 'mean_word_length': 3.6450939457202507, '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': '2870592', 'n_tokens_mistral': 682, 'n_tokens_neox': 664, 'n_words': 159}