diff --git a/Assetfile b/Assetfile index edb50985..c4c50a97 100644 --- a/Assetfile +++ b/Assetfile @@ -49,7 +49,9 @@ input assets.scripts do match %r(^(?!vendor|spec).*\.js$) do modules = proc { |input| input.path.gsub(%r((^app/|lib/|\.js$)), '') } - minispade(string: assets.development?, rewrite_requires: true, module_id_generator: modules) + # why did we use the string strategy for development? makes it impossible to set breakpoints + # minispade(string: assets.development?, rewrite_requires: true, module_id_generator: modules) + minispade(string: false, rewrite_requires: true, module_id_generator: modules) end match %r(^(?!spec).*\.js$) do diff --git a/Gemfile b/Gemfile index 2a324fc8..64632540 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ gem 'rack-ssl', '~> 1.3' gem 'rack-protection', '~> 1.3' gem 'rack-mobile-detect' gem 'sinatra' +gem 'hashr' gem 'rake-pipeline', github: 'livingsocial/rake-pipeline' gem 'rake-pipeline-web-filters', github: 'wycats/rake-pipeline-web-filters' diff --git a/Gemfile.lock b/Gemfile.lock index 762adf84..72b86129 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,15 +1,15 @@ GIT remote: git://github.com/livingsocial/rake-pipeline.git - revision: 65b1e744defa208e313703d89f3453447cc103b2 + revision: a75d96fbadcc659a35a0ae59212e0bc60b58cc54 specs: rake-pipeline (0.8.0) json - rake (~> 10.0.0) + rake (~> 10.1.0) thor GIT remote: git://github.com/wycats/rake-pipeline-web-filters.git - revision: fd8d838491bd6b8de0bab72d90115b9a4f2da8a1 + revision: 7bd283aac83d7c46a8908f089033a6087d7cd68f specs: rake-pipeline-web-filters (0.6.0) rack @@ -18,98 +18,104 @@ GIT GEM remote: http://rubygems.org/ specs: - POpen4 (0.1.4) - Platform (>= 0.4.0) - open4 - Platform (0.4.0) - backports (3.0.3) - celluloid (0.15.2) - timers (~> 1.1.0) - chunky_png (1.2.7) - coderay (1.0.9) - coffee-script (2.2.0) + backports (3.6.3) + celluloid (0.16.0) + timers (~> 4.0.0) + chunky_png (1.3.1) + coderay (1.1.0) + coffee-script (2.3.0) coffee-script-source execjs - coffee-script-source (1.5.0) - compass (0.12.2) + coffee-script-source (1.8.0) + compass (1.0.1) chunky_png (~> 1.2) - fssm (>= 0.2.7) - sass (~> 3.1) - diff-lcs (1.2.1) - eventmachine (1.0.0) - execjs (1.4.0) + compass-core (~> 1.0.1) + compass-import-once (~> 1.0.5) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) + sass (>= 3.3.13, < 3.5) + compass-core (1.0.1) multi_json (~> 1.0) - ffi (1.9.3) - foreman (0.61.0) - thor (>= 0.13.6) - fssm (0.2.10) - guard (1.6.2) - listen (>= 0.6.0) - lumberjack (>= 1.0.2) - pry (>= 0.9.10) - terminal-table (>= 1.4.3) - thor (>= 0.14.6) - json (1.7.7) - libv8 (3.16.14.3) - listen (2.7.9) + sass (>= 3.3.0, < 3.5) + compass-import-once (1.0.5) + sass (>= 3.2, < 3.5) + diff-lcs (1.2.5) + dotenv (0.11.1) + dotenv-deployment (~> 0.0.2) + dotenv-deployment (0.0.2) + execjs (2.2.1) + ffi (1.9.6) + foreman (0.75.0) + dotenv (~> 0.11.1) + thor (~> 0.19.1) + formatador (0.2.5) + guard (2.6.1) + formatador (>= 0.2.4) + listen (~> 2.7) + lumberjack (~> 1.0) + pry (>= 0.9.12) + thor (>= 0.18.1) + hashr (0.0.22) + hitimes (1.2.2) + json (1.8.1) + libv8 (3.16.14.7) + listen (2.7.11) celluloid (>= 0.15.2) rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) - lumberjack (1.0.2) - method_source (0.8.1) - multi_json (1.6.1) - open4 (1.3.0) - pry (0.9.12) - coderay (~> 1.0.5) - method_source (~> 0.8) + lumberjack (1.0.9) + method_source (0.8.2) + multi_json (1.10.1) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) slop (~> 3.4) - puma (2.6.0) + puma (2.9.1) rack (>= 1.1, < 2.0) rack (1.5.2) rack-mobile-detect (0.4.0) rack - rack-protection (1.3.2) + rack-protection (1.5.3) rack - rack-ssl (1.3.3) + rack-ssl (1.4.1) rack rack-test (0.6.2) rack (>= 1.0) - rake (10.0.3) - rb-fsevent (0.9.3) + rake (10.1.1) + rb-fsevent (0.9.4) rb-inotify (0.9.5) ffi (>= 0.5.0) rerun (0.10.0) listen (~> 2.7, >= 2.7.3) - rspec (2.13.0) - rspec-core (~> 2.13.0) - rspec-expectations (~> 2.13.0) - rspec-mocks (~> 2.13.0) - rspec-core (2.13.0) - rspec-expectations (2.13.0) + rspec (2.99.0) + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) + rspec-core (2.99.2) + rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.13.0) - sass (3.2.6) - sinatra (1.3.5) + rspec-mocks (2.99.2) + sass (3.4.5) + sinatra (1.4.5) rack (~> 1.4) - rack-protection (~> 1.3) - tilt (~> 1.3, >= 1.3.3) - sinatra-contrib (1.3.2) + rack-protection (~> 1.4) + tilt (~> 1.3, >= 1.3.4) + sinatra-contrib (1.4.2) backports (>= 2.0) - eventmachine + multi_json rack-protection rack-test - sinatra (~> 1.3.0) + sinatra (~> 1.4.0) tilt (~> 1.3) - slop (3.4.3) - terminal-table (1.4.5) - thor (0.17.0) - tilt (1.3.3) - timers (1.1.0) - uglifier (1.3.0) + slop (3.6.0) + thor (0.19.1) + tilt (1.4.1) + timers (4.0.1) + hitimes + uglifier (2.5.3) execjs (>= 0.3.0) - multi_json (~> 1.0, >= 1.0.2) - yui-compressor (0.9.6) - POpen4 (>= 0.1.4) + json (>= 1.8.0) + yui-compressor (0.12.0) PLATFORMS ruby @@ -119,6 +125,7 @@ DEPENDENCIES compass foreman guard + hashr libv8 (~> 3.16.0) puma rack-mobile-detect diff --git a/assets/scripts/app/app.coffee b/assets/scripts/app/app.coffee index 6514083f..d79fbb61 100644 --- a/assets/scripts/app/app.coffee +++ b/assets/scripts/app/app.coffee @@ -43,7 +43,7 @@ unless window.TravisApplication Travis.SshKey.adapter = Travis.SshKeyAdapter.create() @slider = new Travis.Slider() - @pusher = new Travis.Pusher(Travis.config.pusher_key) if Travis.config.pusher_key + @pusher = new Travis.Pusher(key: Travis.config.pusher_key, host: Travis.config.pusher_host) if Travis.config.pusher_key @tailing = new Travis.Tailing($(window), '#tail', '#log') @toTop = new Travis.ToTop($(window), '.to-top', '#log-container') diff --git a/assets/scripts/app/auth.coffee b/assets/scripts/app/auth.coffee index 43b88517..613c44d7 100644 --- a/assets/scripts/app/auth.coffee +++ b/assets/scripts/app/auth.coffee @@ -109,7 +109,7 @@ window.Auth = Ember.Object.extend expectedOrigin: -> endpoint = @get('endpoint') - if endpoint[0] == '/' then @receivingEnd else endpoint + if endpoint[0] == '/' then @receivingEnd else endpoint.match(/^https?:\/\/[^\/]*/)[0] sendToApp: (name) -> # TODO: this is an ugly solution, we need to do one of 2 things: diff --git a/assets/scripts/app/helpers/helpers.coffee b/assets/scripts/app/helpers/helpers.coffee index 42aa27b7..8f24bbd1 100644 --- a/assets/scripts/app/helpers/helpers.coffee +++ b/assets/scripts/app/helpers/helpers.coffee @@ -86,12 +86,12 @@ require 'config/emoij' _githubReferenceLink: (reference, current, matched) -> owner = matched.owner || current.owner repo = matched.repo || current.repo - "#{reference}" + "#{reference}" _githubUserRegexp: new RegExp("\\B@([\\w-]+)", 'g') _githubUserLink: (reference, username) -> - "#{reference}" + "#{reference}" _githubCommitReferenceRegexp: new RegExp("([\\w-]+)?\\/([\\w-]+)?@([0-9A-Fa-f]+)", 'g') diff --git a/assets/scripts/app/helpers/urls.coffee b/assets/scripts/app/helpers/urls.coffee index ab6f606f..cda9bbc5 100644 --- a/assets/scripts/app/helpers/urls.coffee +++ b/assets/scripts/app/helpers/urls.coffee @@ -3,22 +3,22 @@ "#{Travis.config.api_endpoint}/jobs/#{id}/log.txt?deansi=true" githubPullRequest: (slug, pullRequestNumber) -> - "https://github.com/#{slug}/pull/#{pullRequestNumber}" + "#{Travis.config.source_endpoint}/#{slug}/pull/#{pullRequestNumber}" githubCommit: (slug, sha) -> - "https://github.com/#{slug}/commit/#{sha}" + "#{Travis.config.source_endpoint}/#{slug}/commit/#{sha}" githubRepo: (slug) -> - "https://github.com/#{slug}" + "#{Travis.config.source_endpoint}/#{slug}" githubWatchers: (slug) -> - "https://github.com/#{slug}/watchers" + "#{Travis.config.source_endpoint}/#{slug}/watchers" githubNetwork: (slug) -> - "https://github.com/#{slug}/network" + "#{Travis.config.source_endpoint}/#{slug}/network" githubAdmin: (slug) -> - "https://github.com/#{slug}/settings/hooks#travis_minibucket" + "#{Travis.config.source_endpoint}/#{slug}/settings/hooks#travis_minibucket" statusImage: (slug, branch) -> "#{location.protocol}//#{location.host}/#{slug}.svg" + if branch then "?branch=#{encodeURIComponent(branch)}" else '' diff --git a/assets/scripts/app/models/account.coffee b/assets/scripts/app/models/account.coffee index 03c29f79..513782db 100644 --- a/assets/scripts/app/models/account.coffee +++ b/assets/scripts/app/models/account.coffee @@ -7,7 +7,7 @@ require 'travis/model' _reposCount: Ember.attr(Number, key: 'repos_count') urlGithub: (-> - "https://github.com/#{@get('login')}" + "#{Travis.config.source_endpoint}/#{@get('login')}" ).property() # TODO: maybe it would be good to add a "default" value for Ember.attr diff --git a/assets/scripts/app/models/hook.coffee b/assets/scripts/app/models/hook.coffee index 4126292b..350706aa 100644 --- a/assets/scripts/app/models/hook.coffee +++ b/assets/scripts/app/models/hook.coffee @@ -16,11 +16,11 @@ require 'travis/model' ).property('ownerName', 'name') urlGithub: (-> - "https://github.com/#{@get('slug')}" + "#{Travis.config.source_endpoint}/#{@get('slug')}" ).property() urlGithubAdmin: (-> - "https://github.com/#{@get('slug')}/settings/hooks#travis_minibucket" + "#{Travis.config.source_endpoint}/#{@get('slug')}/settings/hooks#travis_minibucket" ).property() toggle: -> diff --git a/assets/scripts/app/models/job.coffee b/assets/scripts/app/models/job.coffee index 23649a37..58c5d271 100644 --- a/assets/scripts/app/models/job.coffee +++ b/assets/scripts/app/models/job.coffee @@ -102,8 +102,7 @@ require 'travis/model' Travis.pusher.unsubscribe "job-#{@get('id')}" onStateChange: (-> - if @get('state') == 'finished' && Travis.pusher - Travis.pusher.unsubscribe "job-#{@get('id')}" + @unsubscribe() if @get('state') == 'finished' && Travis.pusher ).observes('state') isPropertyLoaded: (key) -> diff --git a/assets/scripts/app/models/repo.coffee b/assets/scripts/app/models/repo.coffee index 91d12919..aa8c1e99 100644 --- a/assets/scripts/app/models/repo.coffee +++ b/assets/scripts/app/models/repo.coffee @@ -5,6 +5,7 @@ require 'travis/model' id: Ember.attr('string') slug: Ember.attr('string') description: Ember.attr('string') + private: Ember.attr('boolean') lastBuildId: Ember.attr('string') lastBuildNumber: Ember.attr(Number) lastBuildState: Ember.attr('string') diff --git a/assets/scripts/app/models/user.coffee b/assets/scripts/app/models/user.coffee index bd2468a3..d6467085 100644 --- a/assets/scripts/app/models/user.coffee +++ b/assets/scripts/app/models/user.coffee @@ -26,7 +26,7 @@ require 'travis/model' ).observes('isSyncing') urlGithub: (-> - "https://github.com/#{@get('login')}" + "#{Travis.config.source_endpoint}/#{@get('login')}" ).property() _rawPermissions: (-> diff --git a/assets/scripts/app/pusher.coffee b/assets/scripts/app/pusher.coffee index faf00514..5cc394b9 100644 --- a/assets/scripts/app/pusher.coffee +++ b/assets/scripts/app/pusher.coffee @@ -1,5 +1,5 @@ -Travis.Pusher = (key) -> - @init(key) # if key +Travis.Pusher = (config) -> + @init(config) this $.extend Travis.Pusher, @@ -10,37 +10,40 @@ $.extend Travis.Pusher, $.extend Travis.Pusher.prototype, active_channels: [] - init: (key) -> + init: (config) -> Pusher.warn = @warn.bind(this) - @pusher = new Pusher(key, encrypted: Travis.Pusher.ENCRYPTED) + Pusher.host = config.host if config.host + @pusher = new Pusher(config.key, encrypted: Travis.Pusher.ENCRYPTED, disableStats: true) @subscribeAll(Travis.Pusher.CHANNELS) if Travis.Pusher.CHANNELS @callbacksToProcess = [] Visibility.change (e, state) => - if state == 'visible' - @processSavedCallbacks() + @processSavedCallbacks() if state == 'visible' setInterval @processSavedCallbacks.bind(this), @processingIntervalWhenHidden subscribeAll: (channels) -> - for channel in channels - name = @prefix(channel) - channel = @pusher.subscribe(channel) - channel.bind_all((event, data) => @receive(event, data)) + @subscribe(channel) for channel in channels subscribe: (channel) -> - console.log("subscribing to #{channel}") + return unless channel channel = @prefix(channel) - @pusher.subscribe(channel).bind_all((event, data) => @receive(event, data)) unless @pusher?.channel(channel) + console.log("subscribing to #{channel}") + unless @pusher?.channel(channel) + @pusher.subscribe(channel).bind_all((event, data) => @receive(event, data)) unsubscribe: (channel) -> - console.log("unsubscribing from #{channel}") + return unless channel channel = @prefix(channel) + console.log("unsubscribing from #{channel}") @pusher.unsubscribe(channel) if @pusher?.channel(channel) prefix: (channel) -> - "#{Travis.Pusher.CHANNEL_PREFIX}#{channel}" + if channel.indexOf(Travis.Pusher.CHANNEL_PREFIX) != 0 + "#{Travis.Pusher.CHANNEL_PREFIX}#{channel}" + else + channel # process pusher messages in batches every 5 minutes when the page is hidden processingIntervalWhenHidden: 1000 * 60 * 5 @@ -84,5 +87,17 @@ $.extend Travis.Pusher.prototype, when 'annotation:created', 'annotation:updated' { annotation: data } - warn: (type, warning) -> - console.warn(warning) + warn: (type, object) -> + console.warn(type, object.error) unless @ignoreWarning(type, object.error) + + ignoreWarning: (type, error) -> + code = error?.data?.code || 0 + message = error?.data?.message || '' + @ignoreCode(code) || @ignoreMessage(message) + + ignoreCode: (code) -> + code == 1006 + + ignoreMessage: (message) -> + message.indexOf('Existing subscription') == 0 or message.indexOf('No current subscription') == 0 + diff --git a/assets/scripts/app/templates/repos/list.hbs b/assets/scripts/app/templates/repos/list.hbs index 41acd7be..17ea50f4 100644 --- a/assets/scripts/app/templates/repos/list.hbs +++ b/assets/scripts/app/templates/repos/list.hbs @@ -20,6 +20,7 @@ {{/if}} {{/with}} + {{#if lastBuildHash.number }}

Duration: {{formatDuration lastBuildDuration}} @@ -28,6 +29,7 @@ Finished: {{formatTime lastBuildFinishedAt}}

+ {{/if}}
{{/with}} diff --git a/assets/scripts/travis.coffee b/assets/scripts/travis.coffee index 9fb252ce..08835a6c 100644 --- a/assets/scripts/travis.coffee +++ b/assets/scripts/travis.coffee @@ -77,9 +77,11 @@ $.extend Travis, config: syncingPageRedirectionTime: 5000 - api_endpoint: $('meta[rel="travis.api_endpoint"]').attr('href') - pusher_key: $('meta[name="travis.pusher_key"]').attr('value') - ga_code: $('meta[name="travis.ga_code"]').attr('value') + api_endpoint: $('meta[rel="travis.api_endpoint"]').attr('href') + source_endpoint: $('meta[rel="travis.source_endpoint"]').attr('href') + pusher_key: $('meta[name="travis.pusher_key"]').attr('value') + pusher_host: $('meta[name="travis.pusher_host"]').attr('value') + ga_code: $('meta[name="travis.ga_code"]').attr('value') code_climate: $('meta[name="travis.code_climate"]').attr('value') ssh_key_enabled: $('meta[name="travis.ssh_key_enabled"]').attr('value') == 'true' code_climate_url: $('meta[name="travis.code_climate_url"]').attr('value') diff --git a/assets/scripts/vendor/pusher.js b/assets/scripts/vendor/pusher.js index 6bf133ac..97881a69 100644 --- a/assets/scripts/vendor/pusher.js +++ b/assets/scripts/vendor/pusher.js @@ -83,7 +83,7 @@ f={isSupported:function(){return!1},connect:function(a,b){var c=Pusher.Util.defe b))&&(!a.disabledTransports||-1===Pusher.Util.arrayIndexOf(a.disabledTransports,b))&&("flash"!==b||!0!==a.disableFlash)?new Pusher.TransportStrategy(b,d,n?n.getAssistant(q):q,Pusher.Util.extend({key:a.key,encrypted:a.encrypted,timeline:a.timeline,ignoreNullOrigin:a.ignoreNullOrigin},e)):f;d=a.def(a,b,c)[1];d.transports=a.transports||{};d.transports[b]=c;return[void 0,d]},transport_manager:b(function(a,b){return new Pusher.TransportManager(b)}),sequential:b(function(a,b){var c=Array.prototype.slice.call(arguments, 2);return new Pusher.SequentialStrategy(c,b)}),cached:b(function(a,b,c){return new Pusher.CachedStrategy(c,a.transports,{ttl:b,timeline:a.timeline,encrypted:a.encrypted})}),first_connected:b(function(a,b){return new Pusher.FirstConnectedStrategy(b)}),best_connected_ever:b(function(){var a=Array.prototype.slice.call(arguments,1);return new Pusher.BestConnectedEverStrategy(a)}),delayed:b(function(a,b,c){return new Pusher.DelayedStrategy(c,{delay:b})}),"if":b(function(a,b,c,d){return new Pusher.IfStrategy(b, c,d)}),is_supported:b(function(a,b){return function(){return b.isSupported()}})};Pusher.StrategyBuilder={build:function(a,b){var c=Pusher.Util.extend({},e,b);return d(a,c)[1].strategy}}}).call(this); -(function(){Pusher.Protocol={decodeMessage:function(b){try{var c=JSON.parse(b.data);if("string"===typeof c.data)try{c.data=JSON.parse(c.data)}catch(a){if(!(a instanceof SyntaxError))throw a;}return c}catch(d){throw{type:"MessageParseError",error:d,data:b.data};}},encodeMessage:function(b){return JSON.stringify(b)},processHandshake:function(b){b=this.decodeMessage(b);if("pusher:connection_established"===b.event){if(!b.data.activity_timeout)throw"No activity timeout specified in handshake";return{action:"connected", +(function(){Pusher.Protocol={decodeMessage:function(b){try{var c=JSON.parse(b.data);if("string"===typeof c.data)try{c.data=JSON.parse(c.data)}catch(a){if(!(a instanceof SyntaxError))throw a;}return c}catch(d){throw{type:"MessageParseError",error:d,data:b.data};}},encodeMessage:function(b){return JSON.stringify(b)},processHandshake:function(b){b=this.decodeMessage(b);if("pusher:connection_established"===b.event){if(!b.data.activity_timeout)b.data.activity_timeout=120;return{action:"connected", id:b.data.socket_id,activityTimeout:1E3*b.data.activity_timeout}}if("pusher:error"===b.event)return{action:this.getCloseAction(b.data),error:this.getCloseError(b.data)};throw"Invalid handshake";},getCloseAction:function(b){return 4E3>b.code?1002<=b.code&&1004>=b.code?"backoff":null:4E3===b.code?"ssl_only":4100>b.code?"refused":4200>b.code?"backoff":4300>b.code?"retry":"refused"},getCloseError:function(b){return 1E3!==b.code&&1001!==b.code?{type:"PusherError",data:{code:b.code,message:b.reason||b.message}}: null}}}).call(this); (function(){function b(a,b){Pusher.EventsDispatcher.call(this);this.id=a;this.transport=b;this.activityTimeout=b.activityTimeout;this.bindListeners()}var c=b.prototype;Pusher.Util.extend(c,Pusher.EventsDispatcher.prototype);c.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()};c.send=function(a){return this.transport.send(a)};c.send_event=function(a,b,c){a={event:a,data:b};c&&(a.channel=c);Pusher.debug("Event sent",a);return this.send(Pusher.Protocol.encodeMessage(a))};c.ping= diff --git a/assets/styles/left/list.sass b/assets/styles/left/list.sass index d5b20aed..767097ba 100644 --- a/assets/styles/left/list.sass +++ b/assets/styles/left/list.sass @@ -83,7 +83,7 @@ span position: relative display: block - top: 45px + top: calc(50% - 10px) left: -15px width: 20px height: 20px diff --git a/config.ru b/config.ru index ab243006..6d575869 100644 --- a/config.ru +++ b/config.ru @@ -26,12 +26,14 @@ use Travis::Web::ApiRedirect do |app| end run Travis::Web::App.build( - environment: ENV['RACK_ENV'] || 'development', - api_endpoint: ENV['API_ENDPOINT'], - pusher_key: ENV['PUSHER_KEY'], - ga_code: ENV['GA_CODE'], - root: File.expand_path('../public', __FILE__), - server_start: Time.now, - caches_enabled: ENV['CACHES_ENABLED'], + environment: ENV['RACK_ENV'] || 'development', + api_endpoint: ENV['API_ENDPOINT'], + source_endpoint: ENV['SOURCE_ENDPOINT'] || 'https://github.com', + pusher_key: ENV['PUSHER_KEY'], + pusher_host: ENV['PUSHER_HOST'] || 'ws.pusherapp.com', + ga_code: ENV['GA_CODE'], + root: File.expand_path('../public', __FILE__), + server_start: Time.now, + caches_enabled: ENV['CACHES_ENABLED'], ssh_key_enabled: ENV['SSH_KEY_ENABLED'] ) diff --git a/lib/travis/assets.rb b/lib/travis/assets.rb index 8f172e7d..27160a90 100644 --- a/lib/travis/assets.rb +++ b/lib/travis/assets.rb @@ -47,7 +47,7 @@ module Travis end def update_version - Travis::Assets::Version.new.update + Travis::Assets::Version.new(roots).update end TYPES.each { |type| define_method(type) { paths[type] } } diff --git a/lib/travis/assets/version.rb b/lib/travis/assets/version.rb index 616d1f81..0e619788 100644 --- a/lib/travis/assets/version.rb +++ b/lib/travis/assets/version.rb @@ -11,10 +11,10 @@ module Travis new.update end - attr_reader :root + attr_reader :roots - def initialize(root = nil) - @root = Pathname.new(root || File.expand_path('.')) + def initialize(roots = nil) + @roots = roots end def read @@ -29,8 +29,12 @@ module Travis protected + def cwd + Pathname.new(File.expand_path('.')) + end + def file - root.join(FILE_NAME) + cwd.join(FILE_NAME) end def write(version) @@ -42,14 +46,16 @@ module Travis end def digest - Digest::MD5.new << `ls -lAR #{sources.join(' ')} | awk '{print $5, $6, $7, $9}'` + Digest::MD5.new << `ls -lAR #{sources.join(' ')} | awk '{ print $5, $6, $7, $8, $9, $10 }'` end def sources - SOURCES.map do |source| - source = root.join(source) - source.to_s if source.exist? - end.compact + roots.map do |root| + SOURCES.map do |source| + source = Pathname.new(root).join(source) + source.to_s if source.exist? + end + end.flatten.compact end end end diff --git a/lib/travis/web.rb b/lib/travis/web.rb index 7d8a6f09..3aa51501 100644 --- a/lib/travis/web.rb +++ b/lib/travis/web.rb @@ -3,6 +3,11 @@ module Travis autoload :Allow, 'travis/web/allow' autoload :ApiRedirect, 'travis/web/api_redirect' autoload :App, 'travis/web/app' + autoload :Config, 'travis/web/config' autoload :SetToken, 'travis/web/set_token' end + + def self.config + @config ||= Travis::Web::Config.new + end end diff --git a/lib/travis/web/app.rb b/lib/travis/web/app.rb index 0fc33d75..31b436d0 100644 --- a/lib/travis/web/app.rb +++ b/lib/travis/web/app.rb @@ -33,7 +33,7 @@ class Travis::Web::App def build(options = {}) builder = Rack::Builder.new if options[:environment] == 'production' - builder.use Rack::SSL + builder.use Rack::SSL, hsts: Travis.config.ssl.hsts end builder.use Rack::Deflater builder.use Rack::Head diff --git a/lib/travis/web/config.rb b/lib/travis/web/config.rb new file mode 100644 index 00000000..902ef9f4 --- /dev/null +++ b/lib/travis/web/config.rb @@ -0,0 +1,50 @@ +require 'hashr' +require 'yaml' + +# Encapsulates the configuration necessary for travis-listener. +# +# Configuration values will be read from +# +# * either ENV['travis_config'] (this variable is set on Heroku by `travis config [env]`, +# see travis-cli) or +# * a local file config/travis.yml which contains the current env key (e.g. development, +# production, test) +# +# The env key can be set through various ENV variables, see Travis::Config.env. +# +module Travis + module Web + class Config < Hashr + class << self + def env + ENV['ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' + end + + def load_env + @load_env ||= YAML.load(ENV['travis_config']) if ENV['travis_config'] + end + + def load_file + @load_file ||= YAML.load_file(filename)[env] if File.exists?(filename) rescue {} + end + + def filename + @filename ||= File.expand_path('config/travis.yml') + end + end + + define ssl: { hsts: true } + + default _access: [:key] + + def initialize(data = nil, *args) + data ||= self.class.load_env || self.class.load_file || {} + super + end + + def env + self.class.env + end + end + end +end diff --git a/public/index.html b/public/index.html index e5348ebe..0d7eb6e9 100644 --- a/public/index.html +++ b/public/index.html @@ -4,8 +4,10 @@ + +