Sha256: d6e4ec0b8558d0c2c2babfc1339e19f321dc2c042aa19280c0f95f3229ce2a02

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

module Janky
  class App < Sinatra::Base
    register Mustache::Sinatra
    register Helpers

    set    :app_file, __FILE__
    enable :static

    set :mustache, {
      :namespace => Janky,
      :views     => File.join(root, "views"),
      :templates => File.join(root, "templates")
    }

    before do
      if organization = github_organization
        github_organization_authenticate!(organization)
      end
    end

    def github_organization
      settings.respond_to?(:github_organization) && settings.github_organization
    end

    def github_team_id
      settings.respond_to?(:github_team_id) && settings.github_team_id
    end

    def authorize_index
      if github_team_id
        github_team_authenticate!(github_team_id)
      end
    end

    def authorize_repo(repo)
      if team_id = (repo.github_team_id || github_team_id)
        github_team_authenticate!(team_id)
      end
    end

    get "/?" do
      authorize_index
      @builds = Build.started.first(50)
      mustache :index
    end

    get "/:build_id/output" do |build_id|
      @build = Build.select(:output).find(build_id)
      authorize_repo(@build.repo)
      mustache :console, :layout => false
    end

    get "/:repo_name" do |repo_name|
      repo = find_repo(repo_name)
      authorize_repo(repo)

      @builds = repo.builds.started.first(50)
      mustache :index
    end

    get %r{^(?!\/auth\/github\/callback)\/([-_\.0-9a-zA-Z]+)\/([-_\.a-zA-z0-9\/]+)} do |repo_name, branch|
      repo = find_repo(repo_name)
      authorize_repo(repo)

      @builds = repo.branch_for(branch).builds.started.first(50)
      mustache :index
    end
  end

  class NoAuth < Sinatra::Base
    register Helpers

    get "/boomtown" do
      raise Error, "boomtown"
    end

    get "/site/sha" do
      `cd /data/janky && git rev-parse HEAD`
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
janky-0.9.13 lib/janky/app.rb
janky-0.9.12 lib/janky/app.rb