Sha256: 6a1929b2c1f6f1bdb3ada58e48b06cd4d040db483f1074be6f6a009737d7a151
Contents?: true
Size: 1.92 KB
Versions: 3
Compression:
Stored size: 1.92 KB
Contents
require 'bait' require 'sinatra' require 'sinatra/streaming' require 'haml' require 'json' require 'bait/pubsub' require 'bait/build' module Bait class Api < Sinatra::Base set :port, 8417 set server: 'thin' if Bait.assets.dynamic? Bait.assets.remove! require 'sinatra/asset_snack' register Sinatra::AssetSnack asset_map '/js/application.js', ['app/js/**/*.js', 'app/js/**/*.coffee'] asset_map '/css/application.css', ['app/css/**/*.css', 'app/css/**/*.scss'] end get '/' do haml :builds end post '/' do if params && params["payload"] push = JSON.parse(params["payload"]) name = push["repository"]["name"] owner_name = push["repository"]["owner"]["name"] Build.create({ name: name, clone_url: "git@github.com:#{owner_name}/#{name}", owner_name: owner_name, owner_email: push["repository"]["owner"]["email"], ref: push["ref"] }).integrate_later end end get '/build' do content_type :json @builds = Bait::Build.all @builds.to_json end post '/build/create' do build = Build.create({ clone_url:params["clone_url"], name:params["clone_url"].split('/').last }) build.integrate_later end delete '/build/:id' do Build.destroy params["id"] end post '/build/:id/retest' do build = Build.find params['id'] build.integrate_later end helpers Sinatra::Streaming get '/events', provides: 'text/event-stream' do stream(:keep_open) do |out| Bait.add_subscriber out out.callback do Bait.remove_subscriber out end end end ## # SimpleCov Passthrough get '/build/:id/coverage/*' do build = Build.find params[:id] if build.simplecov send_file File.join(build.coverage_dir, params[:splat]) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bait-0.5.13 | lib/bait/api.rb |
bait-0.5.12 | lib/bait/api.rb |
bait-0.5.11 | lib/bait/api.rb |