<commit_before>require 'bundler'
Bundler.require

require 'travis/lite/views/repositories'
require 'travis/lite/views/repository'
require 'travis/lite/views/build'
require 'travis/lite/views/job'

require 'travis'

module Travis
  module Lite
    class Application < Sinatra::Base
      register Mustache::Sinatra

      set :mustache, {
        views: File.expand_path('../views/', __FILE__),
        templates: 'templates/',
        namespace: Travis::Lite,
      }

      configure :production do
        disable :raise_exceptions
        disable :show_exceptions

        set :sass, style: :compressed

        require 'newrelic_rpm'
      end

      set :public_folder, File.expand_path('../../../../assets', __FILE__)

      before do
        @request_path = env['REQUEST_PATH']
      end

      get '/style.css' do
        scss :style
      end

      get '/' do
        @repositories = Travis::Repository.current
        @title = 'Latest Builds'
        mustache :repositories
      end

      get '/:user/?' do |user|
        @repositories = Travis::Repository.find_all(owner_name: user)
        @title = "#{user}'s repositories"
        mustache :repositories
      end

      get '/:user/:repo/?' do |user, repo|
        slug = "#{user}/#{repo}"
        @title = slug
        @repository = Travis::Repository.find(slug)
        @builds = @repository.recent_builds
        mustache :repository
      end

      get '/:user/:repo/builds/:build/?' do |user, repo, build|
        slug = "#{user}/#{repo}"
        @title = slug
        @repository = Travis::Repository.find(slug)
        @build = @repository.builds(id: build).first
        if @build.jobs.size == 1
          redirect "#{slug}/jobs/#{@build.jobs.first.id}"
        else
          mustache :build
        end
      end

      get '/:user/:repo/jobs/:job/?' do |user, repo, job|
        slug = "#{user}/#{repo}"
        @title = slug
        @repository = Travis::Repository.find(slug)
        @job = Travis::Job.find(job)
        mustache :job
      end

      error do
        @error = env['sinatra.error']
        erb :error
      end

      error(Travis::Client::NotFound) { not_found }

      not_found { erb :not_found }
    end
  end
end<commit_msg>Move the 404 detection into the routes<commit_after>require 'bundler'
Bundler.require

require 'travis/lite/views/repositories'
require 'travis/lite/views/repository'
require 'travis/lite/views/build'
require 'travis/lite/views/job'

require 'travis'

module Travis
  module Lite
    class Application < Sinatra::Base
      register Mustache::Sinatra

      set :mustache, {
        views: File.expand_path('../views/', __FILE__),
        templates: 'templates/',
        namespace: Travis::Lite,
      }

      configure :production do
        disable :raise_exceptions
        disable :show_exceptions

        set :sass, style: :compressed

        require 'newrelic_rpm'
      end

      set :public_folder, File.expand_path('../../../../assets', __FILE__)

      before do
        @request_path = env['REQUEST_PATH']
      end

      get '/style.css' do
        scss :style
      end

      get '/' do
        @repositories = Travis::Repository.current
        @title = 'Latest Builds'
        mustache :repositories
      end

      get '/:user/?' do |user|
        @repositories = Travis::Repository.find_all(owner_name: user)
        @title = "#{user}'s repositories"
        mustache :repositories
      end

      get '/:user/:repo/?' do |user, repo|
        slug = "#{user}/#{repo}"
        @title = slug
        @repository = Travis::Repository.find(slug)
        @builds = @repository.recent_builds
        mustache :repository
      rescue Travis::Client::NotFound
        not_found
      end

      get '/:user/:repo/builds/:build/?' do |user, repo, build|
        slug = "#{user}/#{repo}"
        @title = slug
        @repository = Travis::Repository.find(slug)
        @build = @repository.builds(id: build).first
        if @build.jobs.size == 1
          redirect "#{slug}/jobs/#{@build.jobs.first.id}"
        else
          mustache :build
        end
      rescue Travis::Client::NotFound
        not_found
      end

      get '/:user/:repo/jobs/:job/?' do |user, repo, job|
        slug = "#{user}/#{repo}"
        @title = slug
        @repository = Travis::Repository.find(slug)
        @job = Travis::Job.find(job)
        mustache :job
      rescue Travis::Client::NotFound
        not_found
      end

      error do
        @error = env['sinatra.error']
        erb :error
      end

      not_found { erb :not_found }
    end
  end
end
{'fraction_non_alphanumeric': 0.12886373530692208, 'fraction_numerical': 0.00108837614279495, 'mean_word_length': 2.0984490896830748, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3197204', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1401, 'n_words': 324}