Merge branch 'master' of github.com:travis-ci/travis-web

Conflicts:
	Gemfile.lock
	public/scripts/app.js
	public/scripts/min/app.js
	public/version
This commit is contained in:
Sven Fuchs 2012-10-16 22:47:43 +02:00
commit 1446fe7aa7
39 changed files with 2033 additions and 2397 deletions

View File

@ -23,7 +23,7 @@ input assets.scripts do
safe_concat assets.vendor_order, 'vendor.js'
end
match 'spec/*.js' do
match '{spec,spec/unit}/*.js' do
concat 'spec/specs.js'
end

26
Gemfile
View File

@ -3,10 +3,6 @@ ruby '1.9.3' rescue nil
source :rubygems
gem 'unicorn'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'yard-sinatra', github: 'rkh/yard-sinatra'
gem 'rack-contrib', github: 'rack/rack-contrib'
gem 'rack-ssl', '~> 1.3'
gem 'rack-cache'
@ -15,35 +11,13 @@ group :development, :test do
end
group :development do
gem 'travis-api', github: 'travis-ci/travis-api'
gem 'travis-core', github: 'travis-ci/travis-core', branch: 'sf-travis-api'
gem 'travis-support', github: 'travis-ci/travis-support'
gem 'gh', github: 'rkh/gh'
gem 'bunny'
gem 'pg', '~> 0.13.2'
gem 'newrelic_rpm', '~> 3.3.0'
gem 'hubble', github: 'roidrage/hubble'
gem 'rake-pipeline', github: 'livingsocial/rake-pipeline', ref: '3465e0e3e1'
gem 'rake-pipeline-web-filters', github: 'wycats/rake-pipeline-web-filters'
gem 'coffee-script'
gem 'compass'
gem 'tilt'
gem 'uglifier'
gem 'debugger'
gem 'foreman'
gem 'rerun'
gem 'rb-fsevent', '~> 0.9.1'
gem 'guard'
end
group :test do
gem 'rspec', '~> 2.11'
gem 'factory_girl', '~> 2.4.0'
gem 'mocha', '~> 0.12'
end

View File

@ -7,86 +7,6 @@ GIT
rake (~> 0.9.0)
thor
GIT
remote: git://github.com/rack/rack-contrib.git
revision: b7e7c38fd02c3b5da91aa57af78b3f571c6ebcd0
specs:
rack-contrib (1.1.0)
rack (>= 0.9.1)
GIT
remote: git://github.com/rkh/gh.git
revision: affde20a4fecb1023f2e7031734b9386a76d22c2
specs:
gh (0.8.0)
addressable
backports (~> 2.3)
faraday (~> 0.8)
multi_json (~> 1.0)
net-http-persistent (>= 2.7)
net-http-pipeline
GIT
remote: git://github.com/rkh/yard-sinatra.git
revision: 3b1064eef407d2d288a5b96d258178a1e67b3b80
specs:
yard-sinatra (1.0.0)
yard (~> 0.7)
GIT
remote: git://github.com/roidrage/hubble.git
revision: f5e6301ac24eabeebaf8f4485d71cdcf93b2f3f8
specs:
hubble (0.1.2)
faraday
json (~> 1.6)
GIT
remote: git://github.com/travis-ci/travis-api.git
revision: 558847f6555202adb7da4f7d31a7b2b80ab4bac2
specs:
travis-api (0.0.1)
backports (~> 2.5)
hubble (~> 0.1)
newrelic_rpm (~> 3.3.0)
pg (~> 0.13.2)
rack-contrib (~> 1.1)
rack-ssl (~> 1.3)
redcarpet (~> 2.1)
sinatra (~> 1.3)
sinatra-contrib (~> 1.3)
thin (~> 1.4)
travis-core
travis-support
GIT
remote: git://github.com/travis-ci/travis-core.git
revision: aae3e646dc73c3196d173baea9265d2b1cb0cd97
branch: sf-travis-api
specs:
travis-core (0.0.1)
actionmailer (~> 3.2.3)
activerecord (~> 3.2.3)
data_migrations (~> 0.0.1)
gh
hashr (~> 0.0.19)
metriks (~> 0.9.7)
multi_json
postmark-rails (~> 0.4.1)
pusher (~> 0.9.2)
railties (~> 3.2.3)
rake (~> 0.9.2.2)
redis (~> 3.0)
rollout (~> 1.1.0)
simple_states (~> 0.1.1)
thor (~> 0.14.6)
GIT
remote: git://github.com/travis-ci/travis-support.git
revision: 7fb3660e0d5705305aa59b30fa74cbcc6248bbad
specs:
travis-support (0.0.1)
GIT
remote: git://github.com/wycats/rake-pipeline-web-filters.git
revision: f28f5809d6a3e580401a0c589d54e6ad28f34a26
@ -98,37 +18,6 @@ GIT
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.8)
actionpack (= 3.2.8)
mail (~> 2.4.4)
actionpack (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.3)
activemodel (3.2.8)
activesupport (= 3.2.8)
builder (~> 3.0.0)
activerecord (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.8)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.2)
arel (3.0.2)
atomic (1.0.1)
avl_tree (1.1.3)
backports (2.6.4)
builder (3.0.3)
bunny (0.8.0)
chunky_png (1.2.6)
coffee-script (2.2.0)
coffee-script-source
@ -139,10 +28,6 @@ GEM
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
daemons (1.1.9)
data_migrations (0.0.1)
activerecord
rake
debugger (1.2.1)
columnize (>= 0.3.1)
debugger-linecache (~> 1.1.1)
@ -150,122 +35,26 @@ GEM
debugger-linecache (1.1.2)
debugger-ruby_core_source (>= 1.1.1)
debugger-ruby_core_source (1.1.4)
diff-lcs (1.1.3)
erubis (2.7.0)
eventmachine (1.0.0)
execjs (1.4.0)
multi_json (~> 1.0)
factory_girl (2.4.2)
activesupport
faraday (0.8.4)
multipart-post (~> 1.1)
foreman (0.60.2)
thor (>= 0.13.6)
fssm (0.2.9)
guard (1.4.0)
listen (>= 0.4.2)
thor (>= 0.14.6)
hashr (0.0.22)
hike (1.2.1)
hitimes (1.1.1)
i18n (0.6.1)
journey (1.0.4)
json (1.7.5)
kgio (2.7.4)
listen (0.5.3)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.1)
metriks (0.9.9.1)
atomic (~> 1.0)
avl_tree (~> 1.1.2)
hitimes (~> 1.1)
mime-types (1.19)
mocha (0.12.7)
metaclass (~> 0.0.1)
multi_json (1.3.6)
multipart-post (1.1.5)
net-http-persistent (2.7)
net-http-pipeline (1.0.1)
newrelic_rpm (3.3.5)
pg (0.13.2)
polyglot (0.3.3)
postmark (0.9.13)
json
rake
postmark-rails (0.4.1)
actionmailer
postmark (>= 0.9.0)
rake
pusher (0.9.4)
multi_json (~> 1.0)
signature (~> 0.1.2)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-protection (1.2.0)
rack
rack-ssl (1.3.2)
rack
rack-test (0.6.2)
rack (>= 1.0)
railties (3.2.8)
actionpack (= 3.2.8)
activesupport (= 3.2.8)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
raindrops (0.10.0)
rake (0.9.2.2)
rb-fsevent (0.9.2)
rdoc (3.12)
json (~> 1.4)
redcarpet (2.2.1)
redis (3.0.2)
rerun (0.7.1)
listen
rollout (1.1.0)
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0)
rspec-core (2.11.1)
rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.3)
sass (3.2.1)
signature (0.1.4)
simple_states (0.1.1)
activesupport
hashr (~> 0.0.10)
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
sinatra-contrib (1.3.1)
backports (>= 2.0)
eventmachine
rack-protection
rack-test
sinatra (~> 1.3.0)
tilt (~> 1.3)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
thin (1.5.0)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.11)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
@ -273,39 +62,21 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
yard (0.8.3)
PLATFORMS
ruby
DEPENDENCIES
bunny
coffee-script
compass
debugger
factory_girl (~> 2.4.0)
foreman
gh!
guard
hubble!
mocha (~> 0.12)
newrelic_rpm (~> 3.3.0)
pg (~> 0.13.2)
rack-cache
rack-contrib!
rack-ssl (~> 1.3)
rake (~> 0.9.2)
rake-pipeline!
rake-pipeline-web-filters!
rb-fsevent (~> 0.9.1)
rerun
rspec (~> 2.11)
sinatra
sinatra-contrib
tilt
travis-api!
travis-core!
travis-support!
uglifier
unicorn
yard-sinatra!

View File

@ -1,3 +1,3 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
guard: bundle exec guard
rerun: rerun -p 'assets/**/*' 'bundle exec rakep'
web: script/server
assets: rerun -x -p 'assets/**/*' 'bundle exec rakep'
#specs: rerun -x -p 'public/**/*' './run_jasmine.coffee public/spec.html'

View File

@ -67,6 +67,7 @@
receiveMessage: (event) ->
if event.origin == @expectedOrigin()
event.data.user.token = event.data.token if event.data.token
@setData(event.data)
console.log("signed in as #{event.data.user.login}")
else

View File

@ -76,18 +76,21 @@ Travis.Store = DS.Store.extend
# if we need sideload becasue we have side records with other events it needs to
# be revised
if type == Travis.Build && json.repository
result = @_loadIncomplete(Travis.Repo, 'repository', json.repository)
@_loadIncomplete(type, root, json[root])
result = @loadIncomplete(Travis.Repo, json.repository)
@loadIncomplete(type, json[root])
_loadIncomplete: (type, root, hash) ->
loadIncomplete: (type, hash) ->
result = @merge(type, hash)
if result && result.clientId
record = @findByClientId(type, result.clientId)
unless record.get('complete')
record.set 'incomplete', true
record.loadedAttributes = Object.keys hash
@_updateAssociations(type, root, hash)
@_updateAssociations(type, type.singularName(), hash)
record
_loadMany: (store, type, json) ->
root = type.pluralName()

View File

@ -8,7 +8,7 @@
<table id="allowed_failure_jobs" class="list">
<caption>
{{t jobs.allowed_failures}}
<a title="What's this?" class="help" name="help-allowed_failures" {{action popup target="view"}}></a>
<a title="What's this?" class="help open-popup" name="help-allowed_failures" {{action popup target="view"}}></a>
</caption>
{{/if}}
<thead>

View File

@ -1,6 +1,8 @@
<a id="github" href="https://github.com/travis-ci" title="Fork me on GitHub">
{{t layouts.application.fork_me}}
</a>
<div id="github-wrapper">
<a id="github" href="https://github.com/travis-ci" title="Fork me on GitHub">
{{t layouts.application.fork_me}}
</a>
</div>
<div id="slider" {{action toggle target="Travis.app.slider"}}>
<div class='icon'></div>&nbsp;

View File

@ -2,7 +2,7 @@
<a href="#" {{action menu target="view"}}></a>
<ul class="menu">
<li>
<a href="#" name="status-images" {{action statusImages target="view"}}>Status Images</a>
<a href="#" name="status-images" class="open-popup" {{action statusImages target="view"}}>Status Images</a>
</li>
{{#if view.canPush}}
<li>

View File

@ -3,6 +3,8 @@
templateName: 'application'
classNames: ['application']
popup: (event) ->
console.log event
localeDidChange: (->
if locale = Travis.app.get('auth.user.locale')
Travis.setLocale(locale)
@ -13,8 +15,9 @@
# TODO: this solves the case of closing menus and popups,
# but I would like to rewrite it later, not sure how
# yet, but this does not seem optimal
if ! $(event.target).parents().andSelf().hasClass('popup')
targetAndParents = $(event.target).parents().andSelf()
if ! ( targetAndParents.hasClass('open-popup') || targetAndParents.hasClass('popup') )
@popupCloseAll()
if ! $(event.target).parents().andSelf().hasClass('menu')
if ! targetAndParents.hasClass('menu')
$('.menu').removeClass('display')

View File

@ -51,7 +51,15 @@
logBinding: 'job.log'
scrollTo: (hash) ->
$('body').scrollTop $(hash).offset().top
# and this is even more weird, when changing hash in URL in firefox
# to other value, for example #L10, it actually scrolls just #main
# element... this is probably some CSS issue, I don't have time to
# investigate at the moment
# TODO: fix this
$('#main').scrollTop 0
# weird, html works in chrome, body in firefox
$('html,body').scrollTop $(hash).offset().top
@set 'controller.lineNumberHash', null
lineNumberHashDidChange: (->

View File

@ -2,6 +2,16 @@
primaryKey: 'id'
id: DS.attr('number')
init: ->
@loadedAttributes = []
@_super.apply this, arguments
get: (name) ->
if @constructor.isAttribute(name) && @get('incomplete') && !@isAttributeLoaded(name)
@loadTheRest()
@_super.apply this, arguments
refresh: ->
if id = @get('id')
store = @get('store')
@ -12,6 +22,9 @@
@set(key, value) unless key is 'id'
this
isAttributeLoaded: (name) ->
@loadedAttributes.contains(name)
isComplete: (->
if @get 'incomplete'
@loadTheRest()
@ -63,3 +76,16 @@
pluralName: ->
Travis.app.store.adapter.pluralize(@singularName())
isAttribute: (name) ->
unless @attributesSaved
@_saveAttributes()
@cachedAttributes.contains(name)
_saveAttributes: ->
@attributesSaved = true
cachedAttributes = []
@eachComputedProperty (name, meta) ->
cachedAttributes.pushObject name if meta.isAttribute
@cachedAttributes = cachedAttributes

View File

@ -92,6 +92,15 @@ describe 'events', ->
payload =
job:
id: 15
repository_id: 1
build_id: 1
commit_id: 1
log_id: 1
number: '1.4'
duration: 55
started_at: '2012-07-02T00:02:00Z'
finished_at: '2012-07-02T00:02:55Z'
config: { rvm: 'jruby' }
$.mockjax
url: '/jobs/15'
@ -105,12 +114,6 @@ describe 'events', ->
repository_id: 1
build_id: 1
commit_id: 1
log_id: 1
number: '1.4'
duration: 55
started_at: '2012-07-02T00:02:00Z'
finished_at: '2012-07-02T00:02:55Z'
config: { rvm: 'jruby' }
waits(100)
runs ->

View File

@ -22,7 +22,7 @@ minispade.require 'app'
runs ->
url = "/#{url}" if url && !url.match(/^\//)
Travis.app.router.route(url)
waits 100
waits 500
runs ->
foo = 'bar'

View File

@ -0,0 +1,72 @@
Travis.Foo = Travis.Model.extend
name: DS.attr('string')
description: DS.attr('string')
record = null
store = null
$.mockjax
url: '/foos/1'
responseTime: 10
responseText: { foo: { id: 1, name: 'foo', description: 'bar' } }
describe 'Travis.Model', ->
beforeEach ->
store = Travis.Store.create()
afterEach ->
store.destroy()
describe 'with incomplete record', ->
beforeEach ->
attrs = {
id: 1
name: 'foo'
}
record = store.loadIncomplete(Travis.Foo, attrs)
it 'shows if attribute is loaded', ->
expect( record.isAttributeLoaded('name') ).toBeTruthy()
expect( record.isAttributeLoaded('description') ).toBeFalsy()
it 'does not trigger a request when getting known attribute', ->
expect( record.get('name') ).toEqual 'foo'
waits 50
runs ->
expect( record.get('complete') ).toBeFalsy()
it 'loads missing data on try to get it', ->
expect( record.get('name') ).toEqual 'foo'
expect( record.get('description') ).toBeNull()
waits 50
runs ->
expect( record.get('description') ).toEqual 'bar'
expect( record.get('complete') ).toBeTruthy()
expect( record.get('isComplete') ).toBeTruthy()
it 'does not set incomplete on the record twice', ->
record.get('description')
waits 50
runs ->
store.loadIncomplete(Travis.Foo, id: 1)
expect( record.get('incomplete') ).toBeFalsy()
describe 'with complete record', ->
beforeEach ->
id = 5
attrs = {
id: id
name: 'foo'
}
store.load(Travis.Foo, id, attrs)
record = Travis.Foo.find(id)
it 'is marked as completed', ->
expect( record.get('complete') ).toBeTruthy()
it 'allows to get regular attribute', ->
expect( record.get('name') ).toEqual 'foo'
it 'allows to check attribute state', ->
expect( record.isAttributeLoaded('name') ).toBeFalsy()

View File

@ -5,7 +5,7 @@
@mixin popup
display: none
position: absolute
position: fixed
z-index: 100
background-color: #fff
border: 10px solid rgba(0, 0, 0, .5)

View File

@ -1,9 +1,20 @@
@import "_mixins/all"
#github-wrapper
position: absolute
z-index: 1001
top: -40px
right: 0px
width: 135px
height: 135px
overflow: hidden
pointer-events: none
#github
display: block
position: absolute
top: 0
z-index: 1001
top: 40px
right: -70px
width: 250px
padding: 3px 0
@ -20,6 +31,8 @@
letter-spacing: -1px
text-shadow: 0 0 10px #522600
pointer-events: auto
@include rotate(45deg)
@include box-shadow(rgba(black, 0.5) 1px 1px 10px, rgba(black, 0.07) 0 0 3px 1px inset)

View File

@ -13,7 +13,7 @@
top: 50%
left: 50%
width: 400px
margin: -230px 0 0 -200px
margin: -200px 0 0 -200px
padding: 20px
@include popup
@ -43,10 +43,9 @@
#status-images
display: none
position: absolute
width: 600px
height: 190px
margin: -145px 0 0 -300px
margin: -95px 0 0 -300px
p
margin: 10px 0

View File

@ -13,8 +13,9 @@ html, body
.application, .application > div
width: 100%
min-height: 100%
@include display-box
@include box-flex(0)
.application > div
overflow-x: auto
#top
position: absolute
@ -22,6 +23,7 @@ html, body
left: 0
width: 100%
height: 40px
z-index: 1000
#page
position: relative
@ -30,7 +32,7 @@ html, body
@include box-align(stretch)
width: 100%
min-height: 100%
top: 40px
margin-top: 40px
#left, #right
@include box-flex(0)
@ -46,6 +48,10 @@ html, body
border-right: 1px solid $color-border-normal
@include box-shadow(transparent 0 0 0 0, $color-border-normal 0 1px 8px 0, transparent 0 0 0 0, transparent 0 0 0 0)
@media screen and (max-width: 980px)
#left
max-width: 300px
#main
@include box-flex(4)
position: relative

View File

@ -4,4 +4,9 @@ ENV['RAILS_ENV'] = ENV['RACK_ENV']
$: << 'lib'
require 'travis/web'
run Travis::Web::App.new
run Travis::Web::App.new(
environment: ENV['RACK_ENV'] || 'development',
api_endpoint: ENV['API_ENDPOINT'],
pusher_key: ENV['PUSHER_KEY'],
root: File.expand_path('../public', __FILE__)
)

View File

@ -1,3 +0,0 @@
[ $PORT ] || export PORT=9292
export API_ENDPOINT="http://api.dev:$PORT/"
export CLIENT_ENDPOINT="http://ci.dev:$PORT/"

View File

@ -1,49 +1,116 @@
require 'rack'
require 'rack/protection/path_traversal'
require 'rack/ssl'
require 'rack/cache'
require 'delegate'
require 'time'
class Travis::Web::App
ASSET_DIRS = %r(/(styles|scripts)/)
DEFAULT_ENDPOINT = 'https://api.travis-ci.org'
DEFAULT_PUSHER_KEY = '23ed642e81512118260e'
autoload :Api, 'travis/web/app/api'
autoload :Assets, 'travis/web/app/assets'
autoload :Config, 'travis/web/app/config'
autoload :Files, 'travis/web/app/files'
autoload :Helpers, 'travis/web/app/helpers'
autoload :Filter, 'travis/web/app/filter'
autoload :Terminal, 'travis/web/app/terminal'
Rack.autoload :SSL, 'rack/ssl'
Rack.autoload :Deflater, 'rack/deflater'
include Terminal
attr_accessor :app
def initialize
config = Config.new
announce(config)
@app = Rack::Builder.app do
use Rack::SSL if config.production?
use Rack::Protection::PathTraversal
use Travis::Web::App::Api, config if config.run_api?
# TODO breaks with wrong content length
# use Rack::Cache, verbose: true, metastore: 'heap:/', entitystore: 'heap:/' if config.production?
use Rack::Deflater if config.deflate?
use Travis::Web::App::Assets, config
use Travis::Web::App::Filter, config
run Travis::Web::App::Files.new
# Simple Rack router that behaves like a hash.
# Key is the path, value the response.
class Router < DelegateClass(Hash)
def initialize
super({})
end
def call(env)
self[env['PATH_INFO']]
end
end
attr_reader :app, :router, :environment, :version, :last_modified, :age, :options, :root
def initialize(options = {})
@options = options
@environment = options.fetch(:environment)
@root = options.fetch(:root)
@router = Router.new
@app = builder.to_app
@version = File.read File.expand_path('version', root)
@last_modified = Time.now
@age = 60 * 60 * 24 * 365
load_routes
end
def call(env)
app.call(env)
end
end
private
def load_routes
each_file { |f| router[route_for(f)] = response_for(f) }
router.default = router['/']
end
def response_for(file)
content = File.read(file)
set_config(content) if index? file
headers = {
'Content-Length' => content.bytesize.to_s,
'Content-Location' => route_for(file),
'Cache-Control' => cache_control(file),
'Content-Location' => route_for(file),
'Content-Type' => mime_type(file),
'ETag' => version,
'Last-Modified' => last_modified.httpdate,
'Expires' => (last_modified + age).httpdate,
'Vary' => ''
}
[ 200, headers, [ content ] ]
end
def each_file
Dir.chdir(root) do
Dir.glob('**/*') { |f| yield f if File.file? f }
end
end
def prefix?(file)
file =~ /^(styles|scripts)\//
end
def index?(file)
file == "index.html"
end
def route_for(file)
file = File.join(version, file) if prefix? file
file = "" if index? file
"/#{file}"
end
def cache_control(file)
case file
when 'index.html' then "public, must-revalidate"
when 'version' then "no-cache"
else "public, max-age=#{age}"
end
end
def mime_type(file)
Rack::Mime.mime_type File.extname(file)
end
def set_config(string)
string.gsub! %r(<meta (rel|name)="(travis\.[^"]*)" (href|value)="([^"]*)"[^>]*>) do
%(<meta #{$1}="#{$2}" #{$3}="#{options[$2.to_sym] || $4}">)
end
string.gsub! %r{(src|href)="(\/?)((styles|scripts)\/[^"]*)"} do
%(#$1="#$2#{version}/#$3")
end
end
def builder
builder = Rack::Builder.new
builder.use Rack::SSL if environment == 'production'
builder.use Rack::Cache
builder.use Rack::Deflater
builder.use Rack::Head
builder.use Rack::ConditionalGet
builder.run router
builder
end
end

View File

@ -1,29 +0,0 @@
require 'travis/api/app'
class Travis::Web::App
class Api
include Helpers
attr_reader :app, :api, :config
def initialize(app, config)
@app = app
@api = Travis::Api::App.new
@config = config
end
def call(env)
if matches?(env['PATH_INFO'])
api.call(map_env(env, config.api_endpoint))
else
app.call(env)
end
end
private
def matches?(path)
path.starts_with?(config.api_endpoint)
end
end
end

View File

@ -1,24 +0,0 @@
class Travis::Web::App
class Assets
include Helpers
attr_reader :app, :config
def initialize(app, config)
@app = app
@config = config
end
def call(env)
path = env['PATH_INFO']
env = map_env(env, config.version) if asset?(path)
app.call(env)
end
private
def asset?(path)
path =~ Travis::Web::App::ASSET_DIRS
end
end
end

View File

@ -1,79 +0,0 @@
class Travis::Web::App
class Config
OPTIONS = %w(ENV API_ENDPOINT CLIENT_ENDPOINT PUSHER_KEY RUN_API WATCH DEFLATE)
def [](key)
send(key)
end
def keys
@keys ||= OPTIONS.map(&:downcase)
end
def each
keys.each do |key|
yield key, send(key)
end
end
def env
config.fetch(:env, 'development')
end
def production?
env == 'production'
end
def run_api?
!!config.fetch(:run_api, config[:api_endpoint].to_s.start_with?('/'))
end
def api_endpoint
config.fetch(:api_endpoint, run_api? ? '/api' : DEFAULT_ENDPOINT).gsub(/:\d+/, '')
end
def client_endpoint
config.fetch(:client_endpoint, '/')
end
def pusher_key
config.fetch(:pusher_key, run_api? ? '' : DEFAULT_PUSHER_KEY)
end
def deflate?
!!config.fetch(:deflate, production?)
end
def watch?
!!config.fetch(:watch, false)
end
alias run_api run_api?
alias deflate deflate?
alias watch watch?
def version
production? ? @version ||= read_version : read_version
end
private
def config
@config ||= Hash[*OPTIONS.map do |key|
[key.downcase.to_sym, cast(ENV[key])] if ENV.key?(key)
end.compact.flatten]
end
def cast(value)
case value
when '1', 'true' then true
when '0', 'false' then false
else value
end
end
def read_version
File.read('public/version').chomp
end
end
end

View File

@ -1,44 +0,0 @@
class Travis::Web::App
class Files < Rack::Cascade
MUST_REVALIDATE = %w(/ /index.html /version)
def self.last_modified
@last_modified ||= File.mtime("public/version").httpdate
end
def initialize
super([public_dir, index])
end
def call(env)
status, headers, body = super(env)
# TODO: temporary hack to make specs work, remove this later properly
headers.delete 'Last-Modified' if env['PATH_INFO'] == '/spec.html'
[status, headers, body]
end
def public_dir
Rack::File.new('public')
end
def index
proc do |env|
status, headers, body = Rack::File.new(nil).tap { |f| f.path = 'public/index.html' }.serving(env)
headers.merge!(cache_headers(env['PATH_INFO'])) # TODO unless development?
[status, headers, body]
end
end
def cache_headers(path)
{ 'Cache-Control' => cache_control(path), 'Last-Modified' => self.class.last_modified }
end
def cache_control(path)
must_revalidate?(path) ? 'public, must-revalidate' : 'public, max-age=31536000'
end
def must_revalidate?(path)
MUST_REVALIDATE.include?(path)
end
end
end

View File

@ -1,43 +0,0 @@
class Travis::Web::App
class Filter
autoload :Config, 'travis/web/app/filter/config'
autoload :Assets, 'travis/web/app/filter/assets'
attr_reader :app, :config
def initialize(app, config)
@app = app
@config = config
end
def call(env)
status, headers, body = app.call(env)
headers, body = filter(headers, body) if content_type?(headers, 'text/html')
[status, headers, body]
end
private
def filter(headers, body)
headers.delete 'Content-Length' # why don't we just set this to the new length?
filtered = []
body.each { |chunk| filtered << filter_chunk(chunk) }
body.close if body.respond_to?(:close)
[headers, filtered]
end
def filter_chunk(string)
filters.inject(string) do |string, filter|
filter.apply? ? filter.apply(string) : string
end
end
def filters
@filters ||= Filter.constants.map { |name| Filter.const_get(name).new(config) }
end
def content_type?(headers, type)
headers.any? { |key, value| key.downcase == 'content-type' and value.start_with?(type) }
end
end
end

View File

@ -1,35 +0,0 @@
class Travis::Web::App
class Filter
class Assets
attr_reader :config
def initialize(config)
@config = config
end
def apply?
true
end
def apply(string)
string = version(string)
string = minify(string) if config.production?
string
end
private
def version(string)
string.gsub(Travis::Web::App::ASSET_DIRS) do
"/#{config.version}/#{$1}/"
end
end
def minify(string)
string.gsub(%r((/javascripts/.*).js)) do
"#{$1}.min.js/"
end
end
end
end
end

View File

@ -1,24 +0,0 @@
class Travis::Web::App
class Filter
class Config
CONFIG_TAG = %r(<meta (rel|name)="([^"]*)" (href|value)="([^"]*)"[^>]*>)
attr_reader :config
def initialize(config)
@config = config
end
def apply?
config.api_endpoint != DEFAULT_ENDPOINT ||
config.pusher_key != DEFAULT_PUSHER_KEY
end
def apply(string)
string.gsub(CONFIG_TAG) do
%(<meta #{$1}="#{$2}" #{$3}="#{config[$2.split('.').last]}">)
end
end
end
end
end

View File

@ -1,11 +0,0 @@
class Travis::Web::App
module Helpers
# TODO what's a better name?
def map_env(env, segment)
segment = "/#{segment}" unless segment[0] == '/'
env['PATH_INFO'] = env['PATH_INFO'].gsub(%r(^#{segment}(?:/)), '')
env['SCRIPT_NAME'] = "#{env['SCRIPT_NAME']}#{segment}"
env
end
end
end

View File

@ -1,17 +0,0 @@
class Travis::Web::App
module Terminal
def announce(config)
config.each do |key, value|
$stderr.puts("#{key.upcase.rjust(15)} = #{colorize(config.send(key))}")
end
end
def colorize(value)
case value
when nil, false, '0' then "\e[31m0\e[0m"
when true, '1' then "\e[32m1\e[0m"
else "\e[33m#{value}\e[0m"
end
end
end
end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8443,7 +8443,18 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
var payload;
payload = {
job: {
id: 15
id: 15,
repository_id: 1,
build_id: 1,
commit_id: 1,
log_id: 1,
number: '1.4',
duration: 55,
started_at: '2012-07-02T00:02:00Z',
finished_at: '2012-07-02T00:02:55Z',
config: {
rvm: 'jruby'
}
}
};
$.mockjax({
@ -8457,15 +8468,7 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
id: 15,
repository_id: 1,
build_id: 1,
commit_id: 1,
log_id: 1,
number: '1.4',
duration: 55,
started_at: '2012-07-02T00:02:00Z',
finished_at: '2012-07-02T00:02:55Z',
config: {
rvm: 'jruby'
}
commit_id: 1
}
});
});
@ -8847,7 +8850,7 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
url = "/" + url;
}
Travis.app.router.route(url);
waits(100);
waits(500);
return runs(function() {
var foo;
return foo = 'bar';
@ -8865,3 +8868,99 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
this.Date.UTC = _Date.UTC;
}).call(this);
(function() {
var record, store;
Travis.Foo = Travis.Model.extend({
name: DS.attr('string'),
description: DS.attr('string')
});
record = null;
store = null;
$.mockjax({
url: '/foos/1',
responseTime: 10,
responseText: {
foo: {
id: 1,
name: 'foo',
description: 'bar'
}
}
});
describe('Travis.Model', function() {
beforeEach(function() {
return store = Travis.Store.create();
});
afterEach(function() {
return store.destroy();
});
describe('with incomplete record', function() {
beforeEach(function() {
var attrs;
attrs = {
id: 1,
name: 'foo'
};
return record = store.loadIncomplete(Travis.Foo, attrs);
});
it('shows if attribute is loaded', function() {
expect(record.isAttributeLoaded('name')).toBeTruthy();
return expect(record.isAttributeLoaded('description')).toBeFalsy();
});
it('does not trigger a request when getting known attribute', function() {
expect(record.get('name')).toEqual('foo');
waits(50);
return runs(function() {
return expect(record.get('complete')).toBeFalsy();
});
});
it('loads missing data on try to get it', function() {
expect(record.get('name')).toEqual('foo');
expect(record.get('description')).toBeNull();
waits(50);
return runs(function() {
expect(record.get('description')).toEqual('bar');
expect(record.get('complete')).toBeTruthy();
return expect(record.get('isComplete')).toBeTruthy();
});
});
return it('does not set incomplete on the record twice', function() {
record.get('description');
waits(50);
return runs(function() {
store.loadIncomplete(Travis.Foo, {
id: 1
});
return expect(record.get('incomplete')).toBeFalsy();
});
});
});
return describe('with complete record', function() {
beforeEach(function() {
var attrs, id;
id = 5;
attrs = {
id: id,
name: 'foo'
};
store.load(Travis.Foo, id, attrs);
return record = Travis.Foo.find(id);
});
it('is marked as completed', function() {
return expect(record.get('complete')).toBeTruthy();
});
it('allows to get regular attribute', function() {
return expect(record.get('name')).toEqual('foo');
});
return it('allows to check attribute state', function() {
return expect(record.isAttributeLoaded('name')).toBeFalsy();
});
});
});
}).call(this);

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
88db3861
d5d950e0

8
script/server Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
cd "$(dirname "$0")/.."
[ $PORT ] || PORT=9292
[ $RACK_ENV ] || RACK_ENV=development
cmd="ruby -I lib -S bundle exec ruby -I lib -S unicorn -p $PORT -c ./config/unicorn.rb"
[[ $RACK_ENV == "development" ]] && exec rerun "$cmd -o 127.0.0.1"
exec $cmd

View File

@ -1,113 +0,0 @@
require 'lib/spec_helper'
describe Travis::Web::App::Config do
let(:config) { Travis::Web::App::Config.new }
before :each do
@env = ENV.clone
ENV.clear
end
after :each do
ENV.replace(@env)
end
describe 'env' do
it 'given ENV=foo it returns foo' do
ENV['ENV'] = 'foo'
config.env.should == 'foo'
end
it 'defaults to development' do
config.env.should == 'development'
end
end
describe 'run_api?' do
it 'given RUN_API=1 it returns true' do
ENV['RUN_API'] = '1'
config.run_api?.should be_true
end
it 'given RUN_API=0 it returns false' do
ENV['RUN_API'] = '0'
config.run_api?.should be_false
end
it 'defaults to true if api_endpoint is local' do
ENV['API_ENDPOINT'] = '/api'
config.run_api?.should be_true
end
it 'defaults to false if api_endpoint is not local' do
ENV['API_ENDPOINT'] = 'https://api.travis-ci.com'
config.run_api?.should be_false
end
end
describe 'api_endpoint' do
it 'given API_ENDPOINT=https://api.travis-ci.com it returns the given url' do
ENV['API_ENDPOINT'] = 'https://api.travis-ci.com'
config.api_endpoint.should == 'https://api.travis-ci.com'
end
it 'defaults to /api if run_api? is true' do
config.stubs(:run_api?).returns(true)
config.api_endpoint.should == '/api'
end
it 'defaults to https://api.travis-ci.org if run_api? is false' do
config.stubs(:run_api?).returns(false)
config.api_endpoint.should == 'https://api.travis-ci.org'
end
end
describe 'client_endpoint' do
it 'given CLIENT_ENDPOINT=/client it returns the given url' do
ENV['CLIENT_ENDPOINT'] = '/client'
config.client_endpoint.should == '/client'
end
it 'defaults to /' do
config.client_endpoint.should == '/'
end
end
describe 'deflate?' do
it 'given DEFLATE=1 it returns true' do
ENV['DEFLATE'] = '1'
config.deflate.should be_true
end
it 'given DEFLATE=0 it returns false' do
ENV['DEFLATE'] = '0'
config.deflate.should be_false
end
it 'defaults to true if env is production' do
config.stubs(:env).returns('production')
config.deflate.should be_true
end
it 'defaults to false if env is not production' do
config.stubs(:env).returns('development')
config.deflate.should be_false
end
end
describe 'watch?' do
it 'given WATCH=1 it returns true' do
ENV['WATCH'] = '1'
config.watch?.should be_true
end
it 'given WATCH=0 it returns false' do
ENV['WATCH'] = '0'
config.watch?.should be_false
end
it 'defaults to false' do
config.watch?.should be_false
end
end
end

View File

@ -1,19 +0,0 @@
# ENV['RACK_ENV'] = ENV['RAILS_ENV'] = ENV['ENV'] = 'test'
require 'rspec'
require 'travis/web'
require 'sinatra/test_helpers'
# require 'logger'
# require 'gh'
# require 'multi_json'
RSpec.configure do |config|
config.mock_framework = :mocha
config.expect_with :rspec, :stdlib
# config.include TestHelpers
# config.before :each do
# set_app Travis::Web::App.new
# end
end