From 5fc8cd78601926646aeee92aa87e15433b9c3d27 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 10 Jul 2013 01:37:37 +0200 Subject: [PATCH 001/185] Use hh-update-user-when-renamed branch in travis-core --- Gemfile | 2 +- Gemfile.lock | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 80d6a333..e318282b 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ ruby '1.9.3' rescue nil source 'https://rubygems.org' gemspec -gem 'travis-core', github: 'travis-ci/travis-core' +gem 'travis-core', github: 'travis-ci/travis-core', branch: 'hh-update-user-when-renamed' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741' gem 'sinatra' diff --git a/Gemfile.lock b/Gemfile.lock index 001a77e1..182a4df4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,7 +32,8 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 95a2c894431665ca8ef3326d9504debbbc0f4f4a + revision: dc8f1b1199078fb82d3c9ef55f55f6c16a6f7edf + branch: hh-update-user-when-renamed specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 3508f25bdf45476979a0345d6a8a4323aaa90b58 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 10 Jul 2013 01:38:07 +0200 Subject: [PATCH 002/185] Nullify logins and rename repos owner when updating/creating user --- lib/travis/api/app/endpoint/authorization.rb | 15 +++++++++++---- .../endpoint/authorization/user_manager_spec.rb | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/travis/api/app/endpoint/authorization.rb b/lib/travis/api/app/endpoint/authorization.rb index 61c34e9e..112316cc 100644 --- a/lib/travis/api/app/endpoint/authorization.rb +++ b/lib/travis/api/app/endpoint/authorization.rb @@ -196,6 +196,8 @@ class Travis::Api::App end class UserManager < Struct.new(:data, :token, :drop_token) + include User::Renaming + def info(attributes = {}) info = data.to_hash.slice('name', 'login', 'gravatar_id') info.merge! attributes.stringify_keys @@ -207,10 +209,15 @@ class Travis::Api::App user = ::User.find_by_github_id(data['id']) info = drop_token ? info : info(github_oauth_token: token) - if user - user.update_attributes info - else - user = ::User.create! info + ActiveRecord::Base.transaction do + if user + rename_repos_owner(user.login, info['login']) + user.update_attributes info + else + user = ::User.create! info + end + + nullify_logins(user.github_id, user.login) end user diff --git a/spec/unit/endpoint/authorization/user_manager_spec.rb b/spec/unit/endpoint/authorization/user_manager_spec.rb index 5ec2d89d..f8067cd0 100644 --- a/spec/unit/endpoint/authorization/user_manager_spec.rb +++ b/spec/unit/endpoint/authorization/user_manager_spec.rb @@ -31,7 +31,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do context 'with existing user' do it 'updates user data' do - user = mock('user') + user = stub('user', login: 'drogus', github_id: 456) User.expects(:find_by_github_id).with(456).returns(user) attributes = { login: 'drogus', github_id: 456, github_oauth_token: 'abc123' }.stringify_keys user.expects(:update_attributes).with(attributes) @@ -42,7 +42,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do context 'without existing user' do it 'creates new user' do - user = mock('user') + user = stub('user', login: 'drogus', github_id: 456) User.expects(:find_by_github_id).with(456).returns(nil) attributes = { login: 'drogus', github_id: 456, github_oauth_token: 'abc123' }.stringify_keys User.expects(:create!).with(attributes).returns(user) From eb1ffaeb77d184557bb77dbf4cc953b10b76c135 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 11 Jul 2013 00:14:47 +0200 Subject: [PATCH 003/185] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 182a4df4..adff2a8c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,7 +32,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: dc8f1b1199078fb82d3c9ef55f55f6c16a6f7edf + revision: 4f702e91b7a792b20082f470029c357f9ecda67d branch: hh-update-user-when-renamed specs: travis-core (0.0.1) From 024eefb569d77a9fa1ae6bc66c010f7d50a7debe Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 10 Jul 2013 22:18:05 -0700 Subject: [PATCH 004/185] Update RSpec to 2.14 This undoes 785c46db53076f18a7edcde18a9ca0c606eaf6c1, since the bug that appeared there is now fixed in RSpec. --- Gemfile | 2 +- Gemfile.lock | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 80d6a333..63da8400 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ gem 'metriks', '0.9.9.5' gem 'ar-octopus', github: 'travis-ci/octopus', require: nil group :test do - gem 'rspec', '~> 2.13.0' + gem 'rspec', '~> 2.13' gem 'factory_girl', '~> 2.4.0' gem 'mocha', '~> 0.12' gem 'database_cleaner', '~> 0.8.0' diff --git a/Gemfile.lock b/Gemfile.lock index 001a77e1..1762a8fa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -225,14 +225,14 @@ GEM rerun (0.8.1) listen (>= 1.0.3) rollout (1.1.0) - rspec (2.13.0) - rspec-core (~> 2.13.0) - rspec-expectations (~> 2.13.0) - rspec-mocks (~> 2.13.0) - rspec-core (2.13.1) - rspec-expectations (2.13.0) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.2) + rspec-expectations (2.14.0) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.13.1) + rspec-mocks (2.14.1) sidekiq (2.5.4) celluloid (~> 0.12.0) connection_pool (~> 0.9.2) @@ -296,7 +296,7 @@ DEPENDENCIES rake (~> 0.9.2) rb-fsevent (~> 0.9.1) rerun - rspec (~> 2.13.0) + rspec (~> 2.13) sentry-raven! sinatra sinatra-contrib From 2909fe28a17168fc733a1f97db291c304d89f9e7 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 10 Jul 2013 22:18:13 -0700 Subject: [PATCH 005/185] Update the gemspec --- travis-api.gemspec | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/travis-api.gemspec b/travis-api.gemspec index daefb3bc..27a94463 100644 --- a/travis-api.gemspec +++ b/travis-api.gemspec @@ -13,8 +13,8 @@ Gem::Specification.new do |s| "Konstantin Haase", "Piotr Sarnacki", "Josh Kalderimis", - "Henrik Hodne", "Mathias Meyer", + "Henrik Hodne", "Andre Arko", "Erik Michaels-Ober", "Steve Richert", @@ -24,12 +24,12 @@ Gem::Specification.new do |s| ] s.email = [ - "me@svenfuchs.com", "konstantin.mailinglists@googlemail.com", + "me@svenfuchs.com", "drogus@gmail.com", "josh.kalderimis@gmail.com", - "me@henrikhodne.com", "meyer@paperplanes.de", + "me@henrikhodne.com", "svenfuchs@artweb-design.de", "andre@arko.net", "sferik@gmail.com", @@ -53,6 +53,7 @@ Gem::Specification.new do |s| "docs/01_cross_origin.md", "lib/tasks/build_update_branch.rake", "lib/tasks/build_update_pull_request_data.rake", + "lib/tasks/encyrpt_all_data.rake", "lib/travis/api/app.rb", "lib/travis/api/app/access_token.rb", "lib/travis/api/app/base.rb", @@ -109,6 +110,7 @@ Gem::Specification.new do |s| "lib/travis/api/app/endpoint/users.rb", "lib/travis/api/app/endpoint/workers.rb", "lib/travis/api/app/extensions.rb", + "lib/travis/api/app/extensions/expose_pattern.rb", "lib/travis/api/app/extensions/scoping.rb", "lib/travis/api/app/extensions/smart_constants.rb", "lib/travis/api/app/extensions/subclass_tracker.rb", @@ -121,6 +123,7 @@ Gem::Specification.new do |s| "lib/travis/api/app/helpers/respond_with.rb", "lib/travis/api/app/middleware.rb", "lib/travis/api/app/middleware/logging.rb", + "lib/travis/api/app/middleware/metriks.rb", "lib/travis/api/app/middleware/rewrite.rb", "lib/travis/api/app/middleware/scope_check.rb", "lib/travis/api/app/responders.rb", @@ -178,6 +181,7 @@ Gem::Specification.new do |s| "spec/unit/endpoint/users_spec.rb", "spec/unit/endpoint/workers_spec.rb", "spec/unit/endpoint_spec.rb", + "spec/unit/extensions/expose_pattern_spec.rb", "spec/unit/extensions/scoping_spec.rb", "spec/unit/extensions/smart_constants_spec.rb", "spec/unit/extensions/subclass_tracker_spec.rb", @@ -185,7 +189,6 @@ Gem::Specification.new do |s| "spec/unit/helpers/json_renderer_spec.rb", "spec/unit/middleware/logging_spec.rb", "spec/unit/middleware/scope_check_spec.rb", - "spec/unit/middleware_spec.rb", "spec/unit/responders/json_spec.rb", "spec/unit/responders/service_spec.rb", "travis-api.gemspec" From 60af7546a25db1fcebd811e49c052b0722d9e953 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 11 Jul 2013 16:37:02 +0200 Subject: [PATCH 006/185] add rack-timeout --- Gemfile | 1 + Gemfile.lock | 2 ++ lib/travis/api/app.rb | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/Gemfile b/Gemfile index 63da8400..24d22e48 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' gem 'rack-cache', '~> 1.2' gem 'rack-attack' +gem 'rack-timeout' gem 'gh' gem 'bunny' gem 'dalli' diff --git a/Gemfile.lock b/Gemfile.lock index 1762a8fa..3fb12413 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -203,6 +203,7 @@ GEM rack rack-test (0.6.2) rack (>= 1.0) + rack-timeout (0.0.4) railties (3.2.13) actionpack (= 3.2.13) activesupport (= 3.2.13) @@ -293,6 +294,7 @@ DEPENDENCIES rack-attack rack-cache (~> 1.2) rack-contrib! + rack-timeout rake (~> 0.9.2) rb-fsevent (~> 0.9.1) rerun diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index fb4ac081..4974f595 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -5,6 +5,7 @@ require 'rack/protection' require 'rack/contrib' require 'rack/cache' require 'rack/attack' +require 'rack-timeout' require 'active_record' require 'redis' require 'gh' @@ -64,6 +65,9 @@ module Travis::Api def initialize @app = Rack::Builder.app do + Rack::Timeout.timeout = 10 + use Rack::Timeout + Rack::Utils::HTTP_STATUS_CODES[420] = "Enhance Your Calm" use Rack::Attack Rack::Attack.blacklist('block client requesting ruby builds') do |req| From 273b328082a195b20a821603bb84b742e73a7f74 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 11 Jul 2013 17:15:03 +0200 Subject: [PATCH 007/185] switch to rack-timeout edge --- Gemfile | 2 +- Gemfile.lock | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 24d22e48..23eeb8e4 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' gem 'rack-cache', '~> 1.2' gem 'rack-attack' -gem 'rack-timeout' +gem 'rack-timeout', github: 'kch/rack-timeout' gem 'gh' gem 'bunny' gem 'dalli' diff --git a/Gemfile.lock b/Gemfile.lock index 3fb12413..b197a797 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,6 +8,12 @@ GIT multi_json (~> 1.0) uuidtools +GIT + remote: git://github.com/kch/rack-timeout.git + revision: 83ca9f5141c1fdcb626820b1601c406e3a3a560a + specs: + rack-timeout (0.1.0beta2) + GIT remote: git://github.com/rack/rack-contrib.git revision: 951760b1710634623ebbccef8d65df9139bb41c2 @@ -203,7 +209,6 @@ GEM rack rack-test (0.6.2) rack (>= 1.0) - rack-timeout (0.0.4) railties (3.2.13) actionpack (= 3.2.13) activesupport (= 3.2.13) @@ -294,7 +299,7 @@ DEPENDENCIES rack-attack rack-cache (~> 1.2) rack-contrib! - rack-timeout + rack-timeout! rake (~> 0.9.2) rb-fsevent (~> 0.9.1) rerun From 2c361e42925d03c0edc88c6b93a66c4ee582beed Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 11 Jul 2013 17:27:32 +0200 Subject: [PATCH 008/185] drop rack-timeout --- Gemfile | 1 - Gemfile.lock | 7 ------- lib/travis/api/app.rb | 4 ---- 3 files changed, 12 deletions(-) diff --git a/Gemfile b/Gemfile index 23eeb8e4..63da8400 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,6 @@ gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' gem 'rack-cache', '~> 1.2' gem 'rack-attack' -gem 'rack-timeout', github: 'kch/rack-timeout' gem 'gh' gem 'bunny' gem 'dalli' diff --git a/Gemfile.lock b/Gemfile.lock index b197a797..1762a8fa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,12 +8,6 @@ GIT multi_json (~> 1.0) uuidtools -GIT - remote: git://github.com/kch/rack-timeout.git - revision: 83ca9f5141c1fdcb626820b1601c406e3a3a560a - specs: - rack-timeout (0.1.0beta2) - GIT remote: git://github.com/rack/rack-contrib.git revision: 951760b1710634623ebbccef8d65df9139bb41c2 @@ -299,7 +293,6 @@ DEPENDENCIES rack-attack rack-cache (~> 1.2) rack-contrib! - rack-timeout! rake (~> 0.9.2) rb-fsevent (~> 0.9.1) rerun diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 4974f595..fb4ac081 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -5,7 +5,6 @@ require 'rack/protection' require 'rack/contrib' require 'rack/cache' require 'rack/attack' -require 'rack-timeout' require 'active_record' require 'redis' require 'gh' @@ -65,9 +64,6 @@ module Travis::Api def initialize @app = Rack::Builder.app do - Rack::Timeout.timeout = 10 - use Rack::Timeout - Rack::Utils::HTTP_STATUS_CODES[420] = "Enhance Your Calm" use Rack::Attack Rack::Attack.blacklist('block client requesting ruby builds') do |req| From f980cb2872a8ad76d4f796355440adfe78b83961 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Thu, 11 Jul 2013 17:36:27 +0200 Subject: [PATCH 009/185] update travis-core for the dalli connection pool chagnes --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1762a8fa..719cd259 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,7 +32,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 95a2c894431665ca8ef3326d9504debbbc0f4f4a + revision: f5d3118ccb77f44b5345c270faa24a0cfbb80e2e specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 387b63739a86964baccab84b193dc1b93439eb90 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Thu, 11 Jul 2013 17:42:58 +0200 Subject: [PATCH 010/185] update core for dalli conn pool changes --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 719cd259..6b155450 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,7 +32,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: f5d3118ccb77f44b5345c270faa24a0cfbb80e2e + revision: 70f0cd27822662d713edef2855a9a3aaa217f311 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 8707f3b35738b1dc53fe13d123f4377eabef47af Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 11 Jul 2013 17:49:21 +0200 Subject: [PATCH 011/185] set X-Middleware-Start for NewRelic --- lib/travis/api/app.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index fb4ac081..a469dab7 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -64,6 +64,8 @@ module Travis::Api def initialize @app = Rack::Builder.app do + use(Rack::Config) { |env| env["HTTP_X_MIDDLEWARE_START"] ||= "t=#{(Time.now.to_f * 1000000).to_i}" } + Rack::Utils::HTTP_STATUS_CODES[420] = "Enhance Your Calm" use Rack::Attack Rack::Attack.blacklist('block client requesting ruby builds') do |req| From 03d124d1b7b16b3c7dd05ff1c305297a3a054ac6 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 11 Jul 2013 18:13:23 +0200 Subject: [PATCH 012/185] metrics for request queue --- lib/travis/api/app.rb | 2 +- lib/travis/api/app/middleware/metriks.rb | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index a469dab7..59e58af8 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -64,7 +64,7 @@ module Travis::Api def initialize @app = Rack::Builder.app do - use(Rack::Config) { |env| env["HTTP_X_MIDDLEWARE_START"] ||= "t=#{(Time.now.to_f * 1000000).to_i}" } + use(Rack::Config) { |env| env['metriks.request.start'] ||= Time.now.utc } Rack::Utils::HTTP_STATUS_CODES[420] = "Enhance Your Calm" use Rack::Attack diff --git a/lib/travis/api/app/middleware/metriks.rb b/lib/travis/api/app/middleware/metriks.rb index cb90f1f4..c8bc07c1 100644 --- a/lib/travis/api/app/middleware/metriks.rb +++ b/lib/travis/api/app/middleware/metriks.rb @@ -7,10 +7,15 @@ class Travis::Api::App include Helpers::Accept before do - env['metriks.request.start'] = Time.now.utc + env['metriks.request.start'] ||= Time.now.utc end after do + if queue_start = time(env['HTTP_X_QUEUE_START']) + time = env['metriks.request.start'] - queue_start + ::Metriks.timer('api.request_queue').update(time) + end + if response.status < 400 time = Time.now.utc - env['metriks.request.start'] if headers['X-Pattern'].present? and headers['X-Endpoint'].present? @@ -21,9 +26,17 @@ class Travis::Api::App end ::Metriks.meter("api.request.#{request.request_method.downcase}").mark end + ::Metriks.meter("api.request.status.#{response.status.to_s[0]}").mark ::Metriks.meter("api.request.version.#{accept_version}").mark end + + def time(value) + value = value.to_f + start = env['metriks.request.start'].to_f + value /= 1000 while value > start + value if value > 946684800 + end end end end From 63b4ac333888844d4f876024150329eefa7087aa Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 11 Jul 2013 18:22:52 +0200 Subject: [PATCH 013/185] also support X-Request-Start --- lib/travis/api/app/middleware/metriks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/metriks.rb b/lib/travis/api/app/middleware/metriks.rb index c8bc07c1..4b9384a8 100644 --- a/lib/travis/api/app/middleware/metriks.rb +++ b/lib/travis/api/app/middleware/metriks.rb @@ -11,7 +11,7 @@ class Travis::Api::App end after do - if queue_start = time(env['HTTP_X_QUEUE_START']) + if queue_start = time(env['HTTP_X_QUEUE_START']) || time(env['HTTP_X_REQUEST_START']) time = env['metriks.request.start'] - queue_start ::Metriks.timer('api.request_queue').update(time) end From 40acdfba4f5834f50217971b4cdd6e03cc763848 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 11 Jul 2013 18:28:44 +0200 Subject: [PATCH 014/185] Revert "also support X-Request-Start" This reverts commit 63b4ac333888844d4f876024150329eefa7087aa. --- lib/travis/api/app/middleware/metriks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/metriks.rb b/lib/travis/api/app/middleware/metriks.rb index 4b9384a8..c8bc07c1 100644 --- a/lib/travis/api/app/middleware/metriks.rb +++ b/lib/travis/api/app/middleware/metriks.rb @@ -11,7 +11,7 @@ class Travis::Api::App end after do - if queue_start = time(env['HTTP_X_QUEUE_START']) || time(env['HTTP_X_REQUEST_START']) + if queue_start = time(env['HTTP_X_QUEUE_START']) time = env['metriks.request.start'] - queue_start ::Metriks.timer('api.request_queue').update(time) end From 04ea79ceec5b324062c839879bc47fa9ff6a5b7f Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 11 Jul 2013 18:31:29 +0200 Subject: [PATCH 015/185] fix time parsing --- lib/travis/api/app/middleware/metriks.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/app/middleware/metriks.rb b/lib/travis/api/app/middleware/metriks.rb index c8bc07c1..cfb22b7b 100644 --- a/lib/travis/api/app/middleware/metriks.rb +++ b/lib/travis/api/app/middleware/metriks.rb @@ -11,7 +11,7 @@ class Travis::Api::App end after do - if queue_start = time(env['HTTP_X_QUEUE_START']) + if queue_start = time(env['HTTP_X_QUEUE_START']) || time(env['HTTP_X_REQUEST_START']) time = env['metriks.request.start'] - queue_start ::Metriks.timer('api.request_queue').update(time) end @@ -35,7 +35,7 @@ class Travis::Api::App value = value.to_f start = env['metriks.request.start'].to_f value /= 1000 while value > start - value if value > 946684800 + Time.at(value) if value > 946684800 end end end From 4df02514dd75f62392498d02b1e2e2c9b59a7646 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Fri, 12 Jul 2013 15:19:13 -0700 Subject: [PATCH 016/185] Update core to get latest dalli changes --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1762a8fa..898dd8d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,7 +32,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 95a2c894431665ca8ef3326d9504debbbc0f4f4a + revision: c710fb1a2416b19cab0fc8186670c1aa549a9dbf specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From b529f61675a52b91a01b7e035a3adcb6374f48a1 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 14 Jul 2013 13:54:30 +0200 Subject: [PATCH 017/185] bundle update for a core build matrix fix --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 81d96cf0..ac3f3829 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,7 +31,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: f8f12caaed106f7447ec723e21d837253025e971 + revision: 6e4fea97354782ea89acc26f1cc291980ee2462c specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -228,7 +228,7 @@ GEM rspec-core (~> 2.14.0) rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) - rspec-core (2.14.2) + rspec-core (2.14.3) rspec-expectations (2.14.0) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.14.1) From 8e1a855812f082547769b437cfef06a2284b6117 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 16 Jul 2013 19:30:16 +0200 Subject: [PATCH 018/185] Don't set content type to JSON by default --- lib/travis/api/app/endpoint.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/travis/api/app/endpoint.rb b/lib/travis/api/app/endpoint.rb index 11c82afc..990c06dc 100644 --- a/lib/travis/api/app/endpoint.rb +++ b/lib/travis/api/app/endpoint.rb @@ -14,7 +14,6 @@ class Travis::Api::App # TODO hmmm? before { flash.clear } - before { content_type :json } error(ActiveRecord::RecordNotFound, Sinatra::NotFound) { not_found } not_found { content_type =~ /json/ ? { 'file' => 'not found' } : 'file not found' } From c194f25a24d4a2707ebe6d8c48ba19c446b18d58 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 16 Jul 2013 19:30:16 +0200 Subject: [PATCH 019/185] Set json content type only when content type is not set --- lib/travis/api/app/endpoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/endpoint.rb b/lib/travis/api/app/endpoint.rb index 11c82afc..47799354 100644 --- a/lib/travis/api/app/endpoint.rb +++ b/lib/travis/api/app/endpoint.rb @@ -14,7 +14,7 @@ class Travis::Api::App # TODO hmmm? before { flash.clear } - before { content_type :json } + after { content_type :json unless content_type } error(ActiveRecord::RecordNotFound, Sinatra::NotFound) { not_found } not_found { content_type =~ /json/ ? { 'file' => 'not found' } : 'file not found' } From 375651e4585475962ff41e59bba158b5940125d2 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 18 Jul 2013 16:36:50 +0200 Subject: [PATCH 020/185] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index adff2a8c..f1855db7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,7 +32,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 4f702e91b7a792b20082f470029c357f9ecda67d + revision: 44a9d7780e3f7bd298b667c885f6c96b822aa2fb branch: hh-update-user-when-renamed specs: travis-core (0.0.1) From b731127ea898243f545979bdaefa3f4dfe707ca7 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Fri, 19 Jul 2013 15:56:31 +0200 Subject: [PATCH 021/185] add RackTimer --- config.ru | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config.ru b/config.ru index 8fb5947a..ad88e886 100644 --- a/config.ru +++ b/config.ru @@ -15,4 +15,20 @@ skip = ['Travis::Memory', 'GH::ResponseWrapper', 'Travis::NewRelic'] target.load_constants! :only => only, :skip => skip, :debug => false end +# https://help.heroku.com/tickets/92756 +class RackTimer + def initialize(app) + @app = app + end + + def call(env) + start_request = Time.now + status, headers, body = @app.call(env) + elapsed = (Time.now - start_request) * 1000 + $stdout.puts("request-id=#{env['HTTP_HEROKU_REQUEST_ID']} measure.rack-request=#{elapsed.round}ms") + [status, headers, body] + end +end + +use RackTimer run Travis::Api::App.new From f6dd1f6f2e292c00df737cb9a372f84f9e3bc6ed Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Mon, 22 Jul 2013 17:40:45 -0700 Subject: [PATCH 022/185] Update 00_overview.md --- docs/00_overview.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/00_overview.md b/docs/00_overview.md index 1a134181..40b31e6f 100644 --- a/docs/00_overview.md +++ b/docs/00_overview.md @@ -12,4 +12,5 @@ The API is currently [JSON](http://en.wikipedia.org/wiki/JSON) only. ## Clients and Libraries -* **[Travis Web](https://github.com/travis-ci/travis-web)**: The official Travis CI client, using [Ember.js](http://emberjs.com/). \ No newline at end of file +* **[Travis Web](https://github.com/travis-ci/travis-web)**: The official Travis CI client, using [Ember.js](http://emberjs.com/). +* **[Travis Node.js](https://github.com/pwmckenna/node-travis-ci)**: The un-official Node.js Travis CI client. From 1387ef34a1342506f2eec8f84950416433b3d4a4 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 23 Jul 2013 17:02:24 +0200 Subject: [PATCH 023/185] Bump travis-core (renaming user fixes from master) --- Gemfile | 2 +- Gemfile.lock | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index e318282b..80d6a333 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ ruby '1.9.3' rescue nil source 'https://rubygems.org' gemspec -gem 'travis-core', github: 'travis-ci/travis-core', branch: 'hh-update-user-when-renamed' +gem 'travis-core', github: 'travis-ci/travis-core' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741' gem 'sinatra' diff --git a/Gemfile.lock b/Gemfile.lock index f1855db7..fb233b5e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,8 +32,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 44a9d7780e3f7bd298b667c885f6c96b822aa2fb - branch: hh-update-user-when-renamed + revision: 0a194c97c857a39c03a5a02eec283e751099d402 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From c3b215a3d3378a4265623b1b27cd2a8b3c0f93a2 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Tue, 23 Jul 2013 09:58:35 -0700 Subject: [PATCH 024/185] Remove link to v1 API documentation --- docs/00_overview.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/00_overview.md b/docs/00_overview.md index 1a134181..5e961760 100644 --- a/docs/00_overview.md +++ b/docs/00_overview.md @@ -1,6 +1,6 @@ # Overview -**This documentation is for the v2 API. However, this endpoint does also serve the [v1 API](http://about.travis-ci.org/docs/dev/api/).** +**This documentation is for the v2 API. However, this endpoint does also serve the v1 API (undocumented).** Welcome to the Travis API documentation. This is the API used by the official [Travis CI](https://next.travis-ci.org) web interface, so everything the web @@ -12,4 +12,4 @@ The API is currently [JSON](http://en.wikipedia.org/wiki/JSON) only. ## Clients and Libraries -* **[Travis Web](https://github.com/travis-ci/travis-web)**: The official Travis CI client, using [Ember.js](http://emberjs.com/). \ No newline at end of file +* **[Travis Web](https://github.com/travis-ci/travis-web)**: The official Travis CI client, using [Ember.js](http://emberjs.com/). From 021ddceafa93e3988ba29dd5b4d09973edc630a2 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 23 Jul 2013 23:43:42 +0200 Subject: [PATCH 025/185] add travis gem --- docs/00_overview.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/00_overview.md b/docs/00_overview.md index c16dc348..ff4025d9 100644 --- a/docs/00_overview.md +++ b/docs/00_overview.md @@ -15,6 +15,7 @@ The API is currently [JSON](http://en.wikipedia.org/wiki/JSON) only. Official, maintained by the Travis CI team: * **[Travis Web](https://github.com/travis-ci/travis-web)**: Web interface and JavaScript library, using [Ember.js](http://emberjs.com/). +* **[travis](https://github.com/travis-ci/travis)**: Command line client and Ruby library. Unofficial: From 5f002cad0eb0bdbbe0308358663499a8bf88975b Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 24 Jul 2013 00:06:54 +0200 Subject: [PATCH 026/185] add php library --- docs/00_overview.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/00_overview.md b/docs/00_overview.md index ff4025d9..ed1428e5 100644 --- a/docs/00_overview.md +++ b/docs/00_overview.md @@ -19,4 +19,5 @@ Official, maintained by the Travis CI team: Unofficial: -* **[Travis Node.js](https://github.com/pwmckenna/node-travis-ci)**: Node.js Travis CI client. +* **[Travis Node.js](https://github.com/pwmckenna/node-travis-ci)**: Node.js client library. +* **[PHP Travis Client](https://github.com/l3l0/php-travis-client)**: PHP client library From d924c15901f3704a646d9320522053f243218d7b Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 24 Jul 2013 00:14:25 +0200 Subject: [PATCH 027/185] add travis-api-wrapper --- docs/00_overview.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/00_overview.md b/docs/00_overview.md index ed1428e5..2e08fe49 100644 --- a/docs/00_overview.md +++ b/docs/00_overview.md @@ -21,3 +21,4 @@ Unofficial: * **[Travis Node.js](https://github.com/pwmckenna/node-travis-ci)**: Node.js client library. * **[PHP Travis Client](https://github.com/l3l0/php-travis-client)**: PHP client library +* **[travis-api-wrapper](https://github.com/cmaujean/travis-api-wrapper)**: Asynchronous Node.js wrapper From 2c9d4f04905714cd379776d669fdd276f6f53644 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 24 Jul 2013 00:29:02 +0200 Subject: [PATCH 028/185] moar libs --- docs/00_overview.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/00_overview.md b/docs/00_overview.md index 2e08fe49..4101f577 100644 --- a/docs/00_overview.md +++ b/docs/00_overview.md @@ -14,11 +14,13 @@ The API is currently [JSON](http://en.wikipedia.org/wiki/JSON) only. Official, maintained by the Travis CI team: -* **[Travis Web](https://github.com/travis-ci/travis-web)**: Web interface and JavaScript library, using [Ember.js](http://emberjs.com/). -* **[travis](https://github.com/travis-ci/travis)**: Command line client and Ruby library. +* **[Travis Web](https://github.com/travis-ci/travis-web)**: Web interface and JavaScript library, using [Ember.js](http://emberjs.com/) +* **[travis](https://github.com/travis-ci/travis)**: Command line client and Ruby library Unofficial: -* **[Travis Node.js](https://github.com/pwmckenna/node-travis-ci)**: Node.js client library. * **[PHP Travis Client](https://github.com/l3l0/php-travis-client)**: PHP client library +* **[Travis Node.js](https://github.com/pwmckenna/node-travis-ci)**: Node.js client library * **[travis-api-wrapper](https://github.com/cmaujean/travis-api-wrapper)**: Asynchronous Node.js wrapper +* **[travis-ci](https://github.com/mmalecki/node-travis-ci)**: Thin Node.js wrapper +* **[TravisMiner](https://github.com/smcintosh/travisminer)**: Ruby library for mining the Travis API \ No newline at end of file From 207a6e3e0438eea7cab2dab3c37e6e0107ff4442 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 27 Jul 2013 01:42:14 +0200 Subject: [PATCH 029/185] Explicitly use self when using info in Authorization --- lib/travis/api/app/endpoint/authorization.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/endpoint/authorization.rb b/lib/travis/api/app/endpoint/authorization.rb index 112316cc..8bc2f296 100644 --- a/lib/travis/api/app/endpoint/authorization.rb +++ b/lib/travis/api/app/endpoint/authorization.rb @@ -207,7 +207,7 @@ class Travis::Api::App def fetch user = ::User.find_by_github_id(data['id']) - info = drop_token ? info : info(github_oauth_token: token) + info = drop_token ? self.info : self.info(github_oauth_token: token) ActiveRecord::Base.transaction do if user From 383d233d9e979742300a6e0033c3d0461c6c4b38 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 2 Aug 2013 13:18:54 +0200 Subject: [PATCH 030/185] Add missing spec for UserManager (when drop_token is true) --- .../endpoint/authorization/user_manager_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/unit/endpoint/authorization/user_manager_spec.rb b/spec/unit/endpoint/authorization/user_manager_spec.rb index f8067cd0..d55c68fb 100644 --- a/spec/unit/endpoint/authorization/user_manager_spec.rb +++ b/spec/unit/endpoint/authorization/user_manager_spec.rb @@ -29,6 +29,19 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do { login: 'drogus', id: 456 }.stringify_keys } + it 'drops the token when drop_token is set to true' do + manager = described_class.new(data, 'abc123', true) + + user = stub('user', login: 'drogus', github_id: 456) + User.expects(:find_by_github_id).with(456).returns(user) + + attributes = { login: 'drogus', github_id: 456 }.stringify_keys + + user.expects(:update_attributes).with(attributes) + + manager.fetch.should == user + end + context 'with existing user' do it 'updates user data' do user = stub('user', login: 'drogus', github_id: 456) From 1c149bcdb49aecfff46f6399c99f594faccb20c0 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Sat, 3 Aug 2013 14:36:42 +0200 Subject: [PATCH 031/185] use client_domain in config --- lib/travis/api/app/endpoint/home.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/endpoint/home.rb b/lib/travis/api/app/endpoint/home.rb index 120c5244..522ec1d9 100644 --- a/lib/travis/api/app/endpoint/home.rb +++ b/lib/travis/api/app/endpoint/home.rb @@ -5,7 +5,7 @@ class Travis::Api::App class Home < Endpoint set :prefix, '/' set :client_config, - host: Travis.config.host, + host: Travis.config.client_domain, shorten_host: Travis.config.shorten_host, assets: Travis.config.assets, pusher: { key: Travis.config.pusher.try(:key) } From e093fde18cd29e655b408c2ccc219c1fd574539c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 5 Aug 2013 02:18:10 +0200 Subject: [PATCH 032/185] Return error with application/json content type by default --- lib/travis/api/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 59e58af8..0c85e17c 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -113,7 +113,7 @@ module Travis::Api app.call(env) rescue if Endpoint.production? - [500, {'Content-Type' => 'text/plain'}, ['Travis encountered an error, sorry :(']] + [500, {'Content-Type' => 'application/json'}, ["{'error': 'Travis encountered an error, sorry :('}"]] else raise end From a87b4238b4ec7cd87ff83abb9eba8636aae88e73 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Mon, 5 Aug 2013 15:13:28 -0700 Subject: [PATCH 033/185] Remove call to Travis::Features.start This was deprecated in travis-ci/travis-core@53ab3c39d835a5e9eff41bf454a1a307cea306b1. --- lib/travis/api/app.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 0c85e17c..2fc29a40 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -137,8 +137,6 @@ module Travis::Api setup_database_connections - Travis::Features.start - if Travis.env == 'production' || Travis.env == 'staging' Sidekiq.configure_client do |config| config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace) From f19de9d134ae8ee42554842d3610c1ff6ba740cf Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 8 Aug 2013 14:25:20 +0200 Subject: [PATCH 034/185] Implement jobs/:id/cancel and builds/:id/cancel endpoints --- Gemfile | 2 +- Gemfile.lock | 3 +- lib/travis/api/app/endpoint/builds.rb | 21 +++++++++++++ lib/travis/api/app/endpoint/jobs.rb | 21 +++++++++++++ spec/integration/v2/builds_spec.rb | 43 +++++++++++++++++++++++++++ spec/integration/v2/jobs_spec.rb | 42 ++++++++++++++++++++++++++ 6 files changed, 130 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 4ebc17f3..aa3d5661 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ ruby '1.9.3' rescue nil source 'https://rubygems.org' gemspec -gem 'travis-core', github: 'travis-ci/travis-core' +gem 'travis-core', github: 'travis-ci/travis-core', branch: 'ps-cancel' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741' gem 'sinatra' diff --git a/Gemfile.lock b/Gemfile.lock index 139f61d9..8de84c79 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,7 +31,8 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 0a194c97c857a39c03a5a02eec283e751099d402 + revision: fa4e4051d35da428d9d67e1c2e2230568f3c2653 + branch: ps-cancel specs: travis-core (0.0.1) actionmailer (~> 3.2.12) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index f956c7ad..98395afc 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -12,6 +12,27 @@ class Travis::Api::App get '/:id' do respond_with service(:find_build, params) end + + post '/:id/cancel' do + service = self.service(:cancel_build, params) + if !service.authorized? + json = { error: { + message: "You don't have access to cancel build(#{params[:id]})" + } } + status 403 + respond_with json + elsif !service.can_cancel? + json = { error: { + message: "The build(#{params[:id]}) can't be canceled", + code: 'cant_cancel' + } } + status 422 + respond_with json + else + service.run + status 204 + end + end end end end diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 966ef7cd..2ac3ba94 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -36,5 +36,26 @@ class Travis::Api::App "#{name}#{'-staging' if Travis.env == 'staging'}.#{Travis.config.host.split('.')[-2, 2].join('.')}" end end + + post '/:id/cancel' do + service = self.service(:cancel_job, params) + if !service.authorized? + json = { error: { + message: "You don't have access to cancel job(#{params[:id]})" + } } + status 403 + respond_with json + elsif !service.can_cancel? + json = { error: { + message: "The job(#{params[:id]}) can't be canceled", + code: 'cant_cancel' + } } + status 422 + respond_with json + else + service.run + status 204 + end + end end end diff --git a/spec/integration/v2/builds_spec.rb b/spec/integration/v2/builds_spec.rb index 8410374f..325ece4f 100644 --- a/spec/integration/v2/builds_spec.rb +++ b/spec/integration/v2/builds_spec.rb @@ -46,4 +46,47 @@ describe 'Builds' do response = get "/builds?repository_id=#{repo.id}&branches=true", {}, headers response.should deliver_json_for(repo.last_finished_builds_by_branches, version: 'v2') end + + describe 'POST /builds/:id/cancel' do + let(:user) { User.where(login: 'svenfuchs').first } + let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) } + + before { + headers.merge! 'HTTP_AUTHORIZATION' => "token #{token}" + user.permissions.create!(repository_id: build.repository.id, :push => true) + } + + context 'when user does not have rights to cancel the build' do + before { user.permissions.destroy_all } + + it 'responds with 403' do + response = post "/builds/#{build.id}/cancel", {}, headers + response.status.should == 403 + end + end + + context 'when build is not cancelable' do + before { build.matrix.each { |j| j.update_attribute(:state, 'passed') } } + + it 'responds with 422' do + response = post "/builds/#{build.id}/cancel", {}, headers + response.status.should == 422 + end + end + + context 'when build can be canceled' do + it 'cancels the build and responds with 204' do + build.matrix.each { |j| j.update_attribute(:state, 'created') } + build.update_attribute(:state, 'created') + + response = nil + expect { + response = post "/builds/#{build.id}/cancel", {}, headers + }.to change { build.reload.state } + response.status.should == 204 + + build.state.should == 'canceled' + end + end + end end diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index 4c7d202e..8dcc7a0c 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -75,4 +75,46 @@ describe 'Jobs' do end end end + + describe 'POST /jobs/:id/cancel' do + let(:user) { User.where(login: 'svenfuchs').first } + let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) } + + before { + headers.merge! 'HTTP_AUTHORIZATION' => "token #{token}" + user.permissions.create!(repository_id: job.repository.id, :push => true) + } + + context 'when user does not have rights to cancel the job' do + before { user.permissions.destroy_all } + + it 'responds with 403' do + response = post "/jobs/#{job.id}/cancel", {}, headers + response.status.should == 403 + end + end + + context 'when job is not cancelable' do + before { job.update_attribute(:state, 'passed') } + + it 'responds with 422' do + response = post "/jobs/#{job.id}/cancel", {}, headers + response.status.should == 422 + end + end + + context 'when job can be canceled' do + it 'cancels the job and responds with 204' do + job.update_attribute(:state, 'created') + + response = nil + expect { + response = post "/jobs/#{job.id}/cancel", {}, headers + }.to change { job.reload.state } + response.status.should == 204 + + job.state.should == 'canceled' + end + end + end end From 6910d6f243ce21d6196c3d5455cc05b5fc92e7f0 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Aug 2013 17:55:59 +0200 Subject: [PATCH 035/185] Bump travis-core (use master branch) --- Gemfile | 2 +- Gemfile.lock | 47 +++++++++++++++++++++++------------------------ 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Gemfile b/Gemfile index aa3d5661..4ebc17f3 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ ruby '1.9.3' rescue nil source 'https://rubygems.org' gemspec -gem 'travis-core', github: 'travis-ci/travis-core', branch: 'ps-cancel' +gem 'travis-core', github: 'travis-ci/travis-core' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741' gem 'sinatra' diff --git a/Gemfile.lock b/Gemfile.lock index 8de84c79..c2466d33 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,8 +31,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: fa4e4051d35da428d9d67e1c2e2230568f3c2653 - branch: ps-cancel + revision: 9adeb30c03674452d09fc551f5e61d40e70e6c72 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -90,12 +89,12 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (3.2.13) - actionpack (= 3.2.13) - mail (~> 2.5.3) - actionpack (3.2.13) - activemodel (= 3.2.13) - activesupport (= 3.2.13) + actionmailer (3.2.14) + actionpack (= 3.2.14) + mail (~> 2.5.4) + actionpack (3.2.14) + activemodel (= 3.2.14) + activesupport (= 3.2.14) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) @@ -103,20 +102,20 @@ GEM rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) - activemodel (3.2.13) - activesupport (= 3.2.13) + activemodel (3.2.14) + activesupport (= 3.2.14) builder (~> 3.0.0) - activerecord (3.2.13) - activemodel (= 3.2.13) - activesupport (= 3.2.13) + activerecord (3.2.14) + activemodel (= 3.2.14) + activesupport (= 3.2.14) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activesupport (3.2.13) - i18n (= 0.6.1) + activesupport (3.2.14) + i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) addressable (2.3.5) arel (3.0.2) - atomic (1.1.10) + atomic (1.1.12) avl_tree (1.1.3) backports (2.8.2) builder (3.0.4) @@ -140,8 +139,8 @@ GEM facter (1.7.2) factory_girl (2.4.2) activesupport - faraday (0.8.7) - multipart-post (~> 1.1) + faraday (0.8.8) + multipart-post (~> 1.2.0) ffi (1.9.0) foreman (0.63.0) dotenv (>= 0.7) @@ -157,7 +156,7 @@ GEM hashr (0.0.22) hike (1.2.3) hitimes (1.2.1) - i18n (0.6.1) + i18n (0.6.5) journey (1.0.4) json (1.8.0) listen (1.2.2) @@ -176,9 +175,9 @@ GEM mime-types (1.23) mocha (0.14.0) metaclass (~> 0.0.1) - multi_json (1.7.7) + multi_json (1.7.9) multipart-post (1.2.0) - net-http-persistent (2.8) + net-http-persistent (2.9) net-http-pipeline (1.0.1) newrelic_rpm (3.6.1.88) pg (0.13.2) @@ -203,9 +202,9 @@ GEM rack rack-test (0.6.2) rack (>= 1.0) - railties (3.2.13) - actionpack (= 3.2.13) - activesupport (= 3.2.13) + railties (3.2.14) + actionpack (= 3.2.14) + activesupport (= 3.2.14) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) From 326f6efa306d8b7f2c3e6fe8802423f1a6ef0b17 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 15 Aug 2013 13:29:00 +0200 Subject: [PATCH 036/185] Bump trvais-core (Disable Request#token encryption) --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c2466d33..9cba8030 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,7 +31,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 9adeb30c03674452d09fc551f5e61d40e70e6c72 + revision: 029a4c6e9659006a7925685db4659dc7cd191dba specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -115,7 +115,7 @@ GEM multi_json (~> 1.0) addressable (2.3.5) arel (3.0.2) - atomic (1.1.12) + atomic (1.1.13) avl_tree (1.1.3) backports (2.8.2) builder (3.0.4) @@ -172,7 +172,7 @@ GEM atomic (~> 1.0) avl_tree (~> 1.1.2) hitimes (~> 1.1) - mime-types (1.23) + mime-types (1.24) mocha (0.14.0) metaclass (~> 0.0.1) multi_json (1.7.9) From 4387867d4666a6ca5beff26dcac2f043d5ec296e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 15 Aug 2013 13:30:34 +0200 Subject: [PATCH 037/185] Update encryption task Don't encrypt Request#token and do encrytion in smaller batches. I also added sleep(10). --- lib/tasks/encyrpt_all_data.rake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/tasks/encyrpt_all_data.rake b/lib/tasks/encyrpt_all_data.rake index 02b05813..dcaf844e 100644 --- a/lib/tasks/encyrpt_all_data.rake +++ b/lib/tasks/encyrpt_all_data.rake @@ -4,7 +4,6 @@ namespace :db do Travis::Database.connect to_encrypt = { - Request => [:token], SslKey => [:private_key], Token => [:token], User => [:github_oauth_token] @@ -12,9 +11,9 @@ namespace :db do encrypted_column = Travis::Model::EncryptedColumn.new to_encrypt.each do |model, column_names| - model.find_in_batches(batch_size: 10000) do |records| + model.find_in_batches(batch_size: 500) do |records| ActiveRecord::Base.transaction do - puts "Encrypted 10000 of #{model} (last_id: #{records.last.id})" + puts "Encrypted 500 of #{model} (last_id: #{records.last.id})" records.each do |record| column_names.each do |column| @@ -25,6 +24,8 @@ namespace :db do end end end + + sleep 10 end end end From e502ca919021a579699606740a90da598da7663d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 21 Aug 2013 00:03:24 +0200 Subject: [PATCH 038/185] Bump travis-support and travis-core --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9cba8030..dfddb396 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,7 +31,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 029a4c6e9659006a7925685db4659dc7cd191dba + revision: e07d1b86f5de4de7ff73e2e72c8263075bcfd564 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -60,7 +60,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: c0add49c71ff3c788b4b7e5b63c11d3896d9847d + revision: 52feaddcd37eb3928083cf43accf3eb2a4194563 specs: travis-support (0.0.1) @@ -266,7 +266,7 @@ GEM thor (0.14.6) tilt (1.4.1) timers (1.1.0) - treetop (1.4.14) + treetop (1.4.15) polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) From 933d5ef81ac1a4b84acf8f27e5cb2cc553a0167a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 21 Aug 2013 02:06:14 +0200 Subject: [PATCH 039/185] Bump travis-support --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index dfddb396..0672d3f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -60,7 +60,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: 52feaddcd37eb3928083cf43accf3eb2a4194563 + revision: 7c69fe727968b31551ce3acbe0d4f2e0e5bc8fa3 specs: travis-support (0.0.1) From 526129b5beef2babdf27c804acf1e3473720ed80 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 21 Aug 2013 11:29:37 +0200 Subject: [PATCH 040/185] Add more metriks (cancel build/job and restart build/job) --- lib/travis/api/app/endpoint/builds.rb | 8 ++++++++ lib/travis/api/app/endpoint/jobs.rb | 8 ++++++++ lib/travis/api/app/endpoint/requests.rb | 1 + 3 files changed, 17 insertions(+) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index 98395afc..3e48cf16 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -14,11 +14,15 @@ class Travis::Api::App end post '/:id/cancel' do + Metriks.meter("api.request.cancel_build").mark + service = self.service(:cancel_build, params) if !service.authorized? json = { error: { message: "You don't have access to cancel build(#{params[:id]})" } } + + Metriks.meter("api.request.cancel_build.unauthorized").mark status 403 respond_with json elsif !service.can_cancel? @@ -26,10 +30,14 @@ class Travis::Api::App message: "The build(#{params[:id]}) can't be canceled", code: 'cant_cancel' } } + + Metriks.meter("api.request.cancel_build.cant_cancel").mark status 422 respond_with json else service.run + + Metriks.meter("api.request.cancel_build.success").mark status 204 end end diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 2ac3ba94..ed5945f4 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -43,6 +43,8 @@ class Travis::Api::App json = { error: { message: "You don't have access to cancel job(#{params[:id]})" } } + + Metriks.meter("api.request.cancel_job.unauthorized").mark status 403 respond_with json elsif !service.can_cancel? @@ -50,12 +52,18 @@ class Travis::Api::App message: "The job(#{params[:id]}) can't be canceled", code: 'cant_cancel' } } + + Metriks.meter("api.request.cancel_job.cant_cancel").mark status 422 respond_with json else service.run + + Metriks.meter("api.request.cancel_job.success").mark status 204 end + + Metriks.meter("api.request.cancel_job").mark end end end diff --git a/lib/travis/api/app/endpoint/requests.rb b/lib/travis/api/app/endpoint/requests.rb index acfec35c..d62b7486 100644 --- a/lib/travis/api/app/endpoint/requests.rb +++ b/lib/travis/api/app/endpoint/requests.rb @@ -4,6 +4,7 @@ class Travis::Api::App class Endpoint class Requests < Endpoint post '/' do + Metriks.meter("api.request.restart").mark respond_with service(:reset_model, params) end end From 37ca20b61c345740d625db1e98f21dd0cd8639e4 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 21 Aug 2013 11:57:00 +0200 Subject: [PATCH 041/185] Measure cancel request on the beginning of the request --- lib/travis/api/app/endpoint/jobs.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index ed5945f4..262d5396 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -38,6 +38,8 @@ class Travis::Api::App end post '/:id/cancel' do + Metriks.meter("api.request.cancel_job").mark + service = self.service(:cancel_job, params) if !service.authorized? json = { error: { @@ -62,8 +64,6 @@ class Travis::Api::App Metriks.meter("api.request.cancel_job.success").mark status 204 end - - Metriks.meter("api.request.cancel_job").mark end end end From 3a90f08d3b5bc70d2cde92dd3be31c44eb9517d3 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Thu, 22 Aug 2013 14:49:24 +0200 Subject: [PATCH 042/185] Disable the /builds endpoint for now. --- lib/travis/api/app/endpoint/builds.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index 3e48cf16..2f01619a 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -4,9 +4,15 @@ class Travis::Api::App class Endpoint class Builds < Endpoint get '/' do - name = params[:branches] ? :find_branches : :find_builds - params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split) - respond_with service(name, params) + if params[:branches] + params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split) + respond_with service(:find_branches, params) + else + respond_with {} + end + # name = params[:branches] ? :find_branches : :find_builds + # params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split) + # respond_with service(name, params) end get '/:id' do From c7110025770a7dc60033328c4212d606837ec4e0 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Thu, 22 Aug 2013 14:59:19 +0200 Subject: [PATCH 043/185] Only return empty builds hash when there are no ids present. --- lib/travis/api/app/endpoint/builds.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index 2f01619a..45575b18 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -4,19 +4,16 @@ class Travis::Api::App class Endpoint class Builds < Endpoint get '/' do - if params[:branches] - params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split) - respond_with service(:find_branches, params) + name = params[:branches] ? :find_branches : :find_builds + params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split) + + if params['ids'].empty? + respond_with({}) else - respond_with {} + respond_with service(name, params) end - # name = params[:branches] ? :find_branches : :find_builds - # params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split) - # respond_with service(name, params) end - get '/:id' do - respond_with service(:find_build, params) end post '/:id/cancel' do From 7fb90f3975dfff31d819148764b63f29936138a8 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Thu, 22 Aug 2013 15:02:39 +0200 Subject: [PATCH 044/185] end end --- lib/travis/api/app/endpoint/builds.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index 45575b18..25945c2b 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -14,8 +14,6 @@ class Travis::Api::App end end - end - post '/:id/cancel' do Metriks.meter("api.request.cancel_build").mark From 8bde2ddb103ee946a98a22de0185567d5f862332 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Thu, 22 Aug 2013 15:05:45 +0200 Subject: [PATCH 045/185] blank --- lib/travis/api/app/endpoint/builds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index 25945c2b..da1a4e9f 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -7,7 +7,7 @@ class Travis::Api::App name = params[:branches] ? :find_branches : :find_builds params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split) - if params['ids'].empty? + if params['ids'].blank? respond_with({}) else respond_with service(name, params) From d141256671faf23f117de7d2caa4fa38d37188ed Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Thu, 22 Aug 2013 15:21:09 +0200 Subject: [PATCH 046/185] Revert my puny changes for now. Will be fixed in travis-web. --- lib/travis/api/app/endpoint/builds.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index da1a4e9f..3e48cf16 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -6,12 +6,11 @@ class Travis::Api::App get '/' do name = params[:branches] ? :find_branches : :find_builds params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split) + respond_with service(name, params) + end - if params['ids'].blank? - respond_with({}) - else - respond_with service(name, params) - end + get '/:id' do + respond_with service(:find_build, params) end post '/:id/cancel' do From d7d6ffc4daa3990dfd16e3378a332894eaaef337 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Fri, 23 Aug 2013 16:53:49 +0200 Subject: [PATCH 047/185] meter content-type --- lib/travis/api/app/middleware/metriks.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/travis/api/app/middleware/metriks.rb b/lib/travis/api/app/middleware/metriks.rb index cfb22b7b..9e9365f9 100644 --- a/lib/travis/api/app/middleware/metriks.rb +++ b/lib/travis/api/app/middleware/metriks.rb @@ -24,6 +24,8 @@ class Travis::Api::App ::Metriks.timer(metric).update(time) ::Metriks.timer('api.requests').update(time) end + type = content_type.split(';', 2).first.to_s.gsub(/\s/,'').gsub(/[^A-z\/]+/, '_').gsub('/', '.') + ::Metriks.meter("api.request.content_type.#{type}") ::Metriks.meter("api.request.#{request.request_method.downcase}").mark end From e1bcd8d2b1ddd2a3966287d101be82b9fd650686 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Fri, 23 Aug 2013 16:59:25 +0200 Subject: [PATCH 048/185] use timer --- lib/travis/api/app/middleware/metriks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/metriks.rb b/lib/travis/api/app/middleware/metriks.rb index 9e9365f9..19e2f8c7 100644 --- a/lib/travis/api/app/middleware/metriks.rb +++ b/lib/travis/api/app/middleware/metriks.rb @@ -25,7 +25,7 @@ class Travis::Api::App ::Metriks.timer('api.requests').update(time) end type = content_type.split(';', 2).first.to_s.gsub(/\s/,'').gsub(/[^A-z\/]+/, '_').gsub('/', '.') - ::Metriks.meter("api.request.content_type.#{type}") + ::Metriks.timer("api.request.content_type.#{type}").update(time) ::Metriks.meter("api.request.#{request.request_method.downcase}").mark end From 60d37634b212aaa1ce4a3f614edd5dec71306fd4 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Fri, 23 Aug 2013 17:10:51 +0200 Subject: [PATCH 049/185] handle missing content-type --- lib/travis/api/app/middleware/metriks.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/app/middleware/metriks.rb b/lib/travis/api/app/middleware/metriks.rb index 19e2f8c7..854fe2f5 100644 --- a/lib/travis/api/app/middleware/metriks.rb +++ b/lib/travis/api/app/middleware/metriks.rb @@ -24,8 +24,12 @@ class Travis::Api::App ::Metriks.timer(metric).update(time) ::Metriks.timer('api.requests').update(time) end - type = content_type.split(';', 2).first.to_s.gsub(/\s/,'').gsub(/[^A-z\/]+/, '_').gsub('/', '.') - ::Metriks.timer("api.request.content_type.#{type}").update(time) + if content_type + type = content_type.split(';', 2).first.to_s.gsub(/\s/,'').gsub(/[^A-z\/]+/, '_').gsub('/', '.') + ::Metriks.timer("api.request.content_type.#{type}").update(time) + else + ::Metriks.timer("api.request.content_type.none").update(time) + end ::Metriks.meter("api.request.#{request.request_method.downcase}").mark end From c7c33ed2aa84174f6959b63faf60b9d56311e881 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Fri, 23 Aug 2013 17:39:47 +0200 Subject: [PATCH 050/185] also treat empty content type as no content type --- lib/travis/api/app/middleware/metriks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/metriks.rb b/lib/travis/api/app/middleware/metriks.rb index 854fe2f5..4f8cecb6 100644 --- a/lib/travis/api/app/middleware/metriks.rb +++ b/lib/travis/api/app/middleware/metriks.rb @@ -24,7 +24,7 @@ class Travis::Api::App ::Metriks.timer(metric).update(time) ::Metriks.timer('api.requests').update(time) end - if content_type + if content_type.present? type = content_type.split(';', 2).first.to_s.gsub(/\s/,'').gsub(/[^A-z\/]+/, '_').gsub('/', '.') ::Metriks.timer("api.request.content_type.#{type}").update(time) else From 618241a458df9f17394252a03d99b6c9c7f18ce5 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Mon, 26 Aug 2013 15:30:07 +0200 Subject: [PATCH 051/185] Add an uptime endpoint for Pingdom. Sends a simple database query to see if we can still connect to the database. Should help us detect issues like yesterday's EC2 issues earlier. --- lib/travis/api/app/endpoint/uptime.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/travis/api/app/endpoint/uptime.rb diff --git a/lib/travis/api/app/endpoint/uptime.rb b/lib/travis/api/app/endpoint/uptime.rb new file mode 100644 index 00000000..9b8b618f --- /dev/null +++ b/lib/travis/api/app/endpoint/uptime.rb @@ -0,0 +1,16 @@ +require 'travis/api/app' + +class Travis::Api::App + class Endpoint + class Uptime < Endpoint + get '/' do + begin + ActiveRecord::Base.connection.execute('select 1') + [200, "OK"] + rescue => e + [500, "Error: #{e.message}"] + end + end + end + end +end From 9d26844eaa3e2e6472c9c11a1787f86ac27fc360 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Mon, 26 Aug 2013 17:29:10 +0200 Subject: [PATCH 052/185] Add tests for /uptime. --- lib/travis/api/app/endpoint/uptime.rb | 4 ++-- spec/integration/uptime_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 spec/integration/uptime_spec.rb diff --git a/lib/travis/api/app/endpoint/uptime.rb b/lib/travis/api/app/endpoint/uptime.rb index 9b8b618f..dc342df5 100644 --- a/lib/travis/api/app/endpoint/uptime.rb +++ b/lib/travis/api/app/endpoint/uptime.rb @@ -7,8 +7,8 @@ class Travis::Api::App begin ActiveRecord::Base.connection.execute('select 1') [200, "OK"] - rescue => e - [500, "Error: #{e.message}"] + rescue Exception => e + return [500, "Error: #{e.message}"] end end end diff --git a/spec/integration/uptime_spec.rb b/spec/integration/uptime_spec.rb new file mode 100644 index 00000000..055e2166 --- /dev/null +++ b/spec/integration/uptime_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe 'Uptime' do + after do + ActiveRecord::Base.connection.unstub(:execute) + end + + it 'returns a 200 and ok when the request was successful' do + response = get '/uptime' + response.status.should == 200 + response.body.should == "OK" + end + + it "returns a 500 when the query wasn't successful" do + ActiveRecord::Base.connection.stubs(:execute).raises(StandardError, 'error!') + response = get '/uptime' + response.status.should == 500 + response.body.should == "Error: error!" + end +end From fab5d3588c0ccdd20e4be7821a1bea21246c52f0 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Tue, 27 Aug 2013 13:35:30 +0200 Subject: [PATCH 053/185] Bump travis-core. Includes updated payload for repositories. --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0672d3f2..1683863f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,7 +31,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: e07d1b86f5de4de7ff73e2e72c8263075bcfd564 + revision: c400ecf505d5e0cc0d812af5e1f2a0eaae0810fc specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 7f63a5a81c14596db751ac3db7f393c1b98ea23a Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Tue, 27 Aug 2013 14:32:51 +0200 Subject: [PATCH 054/185] Bump travis-core. Fixes avatar_url for the User. --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1683863f..9308ca68 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,7 +31,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: c400ecf505d5e0cc0d812af5e1f2a0eaae0810fc + revision: 0b939751455e48fdfbe4618898774030a9bed839 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 7e8e2123214e9099571e14cff03c0640ce1587ef Mon Sep 17 00:00:00 2001 From: Tim Carey-Smith Date: Sun, 1 Sep 2013 23:55:11 +1200 Subject: [PATCH 055/185] Use valid JSON for error responses --- lib/travis/api/app.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 2fc29a40..d2ee1420 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -32,6 +32,8 @@ module Travis::Api Rack.autoload :SSL, 'rack/ssl' + ERROR_RESPONSE = JSON.generate(error: 'Travis encountered an error, sorry :(') + # Used to track if setup already ran. def self.setup? @setup ||= false @@ -113,7 +115,7 @@ module Travis::Api app.call(env) rescue if Endpoint.production? - [500, {'Content-Type' => 'application/json'}, ["{'error': 'Travis encountered an error, sorry :('}"]] + [500, {'Content-Type' => 'application/json'}, [ERROR_RESPONSE]] else raise end From 6412a07ad1becb984e767022edf558fe4d7f4d8d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 22 Aug 2013 15:47:24 +0200 Subject: [PATCH 056/185] Disable new relic --- Gemfile.lock | 2 -- lib/travis/api/app/base.rb | 4 ---- travis-api.gemspec | 2 -- 3 files changed, 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9308ca68..16a1d775 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,7 +75,6 @@ PATH specs: travis-api (0.0.1) backports (~> 2.5) - newrelic_rpm (~> 3.6.1.88) pg (~> 0.13.2) rack-contrib (~> 1.1) rack-ssl (~> 1.3, >= 1.3.3) @@ -179,7 +178,6 @@ GEM multipart-post (1.2.0) net-http-persistent (2.9) net-http-pipeline (1.0.1) - newrelic_rpm (3.6.1.88) pg (0.13.2) polyglot (0.3.3) pry (0.9.12.2) diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index 4fbf40c8..70804953 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -7,10 +7,6 @@ class Travis::Api::App class Base < Sinatra::Base register Extensions::SmartConstants - configure :production do - require 'newrelic_rpm' - end - error NotImplementedError do content_type :txt status 501 diff --git a/travis-api.gemspec b/travis-api.gemspec index 27a94463..08e03222 100644 --- a/travis-api.gemspec +++ b/travis-api.gemspec @@ -47,7 +47,6 @@ Gem::Specification.new do |s| "Rakefile", "config.ru", "config/database.yml", - "config/newrelic.yml", "config/unicorn.rb", "docs/00_overview.md", "docs/01_cross_origin.md", @@ -199,7 +198,6 @@ Gem::Specification.new do |s| s.add_dependency 'backports', '~> 2.5' s.add_dependency 'pg', '~> 0.13.2' - s.add_dependency 'newrelic_rpm', '~> 3.6.1.88' s.add_dependency 'thin', '~> 1.4' s.add_dependency 'sinatra', '~> 1.3' s.add_dependency 'sinatra-contrib', '~> 1.3' From 97958a4ce43deeae57930b05fcde095657d9ed0e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 1 Sep 2013 23:52:51 +0200 Subject: [PATCH 057/185] Try nginx --- .buildpacks | 1 + Procfile | 2 +- config/puma-config.rb | 9 +++++++++ lib/travis/api/app.rb | 2 ++ script/server | 2 +- 5 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 config/puma-config.rb diff --git a/.buildpacks b/.buildpacks index eb20a5d0..36201cad 100644 --- a/.buildpacks +++ b/.buildpacks @@ -1,2 +1,3 @@ https://github.com/heroku/heroku-buildpack-ruby.git https://github.com/drogus/last-commit-sha-buildpack.git +https://github.com/ryandotsmith/nginx-buildpack.git diff --git a/Procfile b/Procfile index bbb53736..42675c0c 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -web: bundle exec ./script/server +web: bin/start-nginx bundle exec ./script/server console: bundle exec ./script/console diff --git a/config/puma-config.rb b/config/puma-config.rb new file mode 100644 index 00000000..38d7628e --- /dev/null +++ b/config/puma-config.rb @@ -0,0 +1,9 @@ +root = File.expand_path('../..', __FILE__) + +rackup "#{root}/config.ru" + +bind 'unix:///tmp/nginx.socket' + +environment ENV['RACK_ENV'] || 'development' + +threads 0, 16 diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 2fc29a40..8b6a8ab6 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -12,6 +12,7 @@ require 'raven' require 'sidekiq' require 'metriks/reporter/logger' require 'travis/support/log_subscriber/active_record_metrics' +require 'fileutils' # Rack class implementing the HTTP API. # Instances respond to #call. @@ -45,6 +46,7 @@ module Travis::Api def self.setup(options = {}) setup! unless setup? Endpoint.set(options) if options + FileUtils.touch('/tmp/app-initialized') end def self.new(options = {}) diff --git a/script/server b/script/server index a17c4245..05517d05 100755 --- a/script/server +++ b/script/server @@ -3,6 +3,6 @@ cd "$(dirname "$0")/.." [ $PORT ] || PORT=3000 [ $RACK_ENV ] || RACK_ENV=development -cmd="ruby -I lib -S bundle exec ruby -I lib -S puma config.ru -p $PORT -e $RACK_ENV --threads 0:16" +cmd="ruby -I lib -S bundle exec ruby -I lib -S puma -C config/puma-config.rb" [[ $RACK_ENV == "development" ]] && exec rerun "$cmd -b tcp://127.0.0.1:$PORT" exec $cmd From 0c3e12dfa3b3b403acf0d87d7220e451dbca2a1e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 2 Sep 2013 10:15:53 +0200 Subject: [PATCH 058/185] Revert "Disable new relic" This reverts commit 6412a07ad1becb984e767022edf558fe4d7f4d8d. --- Gemfile.lock | 2 ++ lib/travis/api/app/base.rb | 4 ++++ travis-api.gemspec | 2 ++ 3 files changed, 8 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 16a1d775..53a779da 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,6 +75,7 @@ PATH specs: travis-api (0.0.1) backports (~> 2.5) + newrelic_rpm (~> 3.6.6) pg (~> 0.13.2) rack-contrib (~> 1.1) rack-ssl (~> 1.3, >= 1.3.3) @@ -178,6 +179,7 @@ GEM multipart-post (1.2.0) net-http-persistent (2.9) net-http-pipeline (1.0.1) + newrelic_rpm (3.6.6.147) pg (0.13.2) polyglot (0.3.3) pry (0.9.12.2) diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index 70804953..4fbf40c8 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -7,6 +7,10 @@ class Travis::Api::App class Base < Sinatra::Base register Extensions::SmartConstants + configure :production do + require 'newrelic_rpm' + end + error NotImplementedError do content_type :txt status 501 diff --git a/travis-api.gemspec b/travis-api.gemspec index 08e03222..d6d027fe 100644 --- a/travis-api.gemspec +++ b/travis-api.gemspec @@ -47,6 +47,7 @@ Gem::Specification.new do |s| "Rakefile", "config.ru", "config/database.yml", + "config/newrelic.yml", "config/unicorn.rb", "docs/00_overview.md", "docs/01_cross_origin.md", @@ -198,6 +199,7 @@ Gem::Specification.new do |s| s.add_dependency 'backports', '~> 2.5' s.add_dependency 'pg', '~> 0.13.2' + s.add_dependency 'newrelic_rpm', '~> 3.6.6' s.add_dependency 'thin', '~> 1.4' s.add_dependency 'sinatra', '~> 1.3' s.add_dependency 'sinatra-contrib', '~> 1.3' From 732b24e1e554fd5a1858cbfd0c32826f4a67d7e5 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 2 Sep 2013 09:26:34 +0200 Subject: [PATCH 059/185] Switch to unicorn --- Gemfile | 2 +- Gemfile.lock | 10 +++++++--- config/unicorn.rb | 7 +++++++ script/server | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 4ebc17f3..77295f28 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: ' gem 'sinatra' gem 'sinatra-contrib', require: nil #github: 'sinatra/sinatra-contrib', require: nil -gem 'puma', '2.3.1' +gem 'unicorn' gem 'sentry-raven', github: 'getsentry/raven-ruby' gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' diff --git a/Gemfile.lock b/Gemfile.lock index 53a779da..fe2abf3f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -159,6 +159,7 @@ GEM i18n (0.6.5) journey (1.0.4) json (1.8.0) + kgio (2.8.0) listen (1.2.2) rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) @@ -186,8 +187,6 @@ GEM coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.4) - puma (2.3.1) - rack (>= 1.1, < 2.0) pusher (0.11.3) multi_json (~> 1.0) signature (~> 0.1.6) @@ -209,6 +208,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) + raindrops (0.11.0) rake (0.9.6) rb-fsevent (0.9.3) rb-inotify (0.9.0) @@ -270,6 +270,10 @@ GEM polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) + unicorn (4.6.3) + kgio (~> 2.6) + rack + raindrops (~> 0.7) uuidtools (2.1.4) yard (0.8.6.2) @@ -288,7 +292,6 @@ DEPENDENCIES micro_migrations! mocha (~> 0.12) pry - puma (= 2.3.1) rack-attack rack-cache (~> 1.2) rack-contrib! @@ -303,4 +306,5 @@ DEPENDENCIES travis-core! travis-sidekiqs! travis-support! + unicorn yard-sinatra! diff --git a/config/unicorn.rb b/config/unicorn.rb index 45bae390..be3065d1 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -2,3 +2,10 @@ worker_processes 4 # amount of unicorn workers to spin up timeout 30 # restarts workers that hang for 15 seconds + +listen '/tmp/nginx.socket', backlog: 1024 + +require 'fileutils' +before_fork do |server,worker| + FileUtils.touch('/tmp/app-initialized') +end diff --git a/script/server b/script/server index 05517d05..3c88cd81 100755 --- a/script/server +++ b/script/server @@ -3,6 +3,6 @@ cd "$(dirname "$0")/.." [ $PORT ] || PORT=3000 [ $RACK_ENV ] || RACK_ENV=development -cmd="ruby -I lib -S bundle exec ruby -I lib -S puma -C config/puma-config.rb" -[[ $RACK_ENV == "development" ]] && exec rerun "$cmd -b tcp://127.0.0.1:$PORT" +cmd="ruby -I lib -S bundle exec ruby -I lib -S unicorn config.ru -E $RACK_ENV -c config/unicorn.rb" +[[ $RACK_ENV == "development" ]] && exec rerun "$cmd -l 127.0.0.1:$PORT" exec $cmd From 94922cd62504b8c1f6e7d07ef32f6354a00dcc5b Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 2 Sep 2013 12:29:13 +0200 Subject: [PATCH 060/185] Start new relic manually --- lib/travis/api/app/base.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index 4fbf40c8..35e44766 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -9,6 +9,8 @@ class Travis::Api::App configure :production do require 'newrelic_rpm' + ::NewRelic::Agent.manual_start() + ::NewRelic::Agent.after_fork(:force_reconnect => true) end error NotImplementedError do From d549ead325b2861c2b33cd8f1236da1b4fedd48a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 2 Sep 2013 13:23:50 +0200 Subject: [PATCH 061/185] Fix wrong memcache servers code --- lib/travis/api/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 8b6a8ab6..8ae5f30b 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -86,7 +86,7 @@ module Travis::Api use ActiveRecord::QueryCache memcache_servers = ENV['MEMCACHE_SERVERS'] - if Travis::Features.feature_active?(:use_rack_cache) && memcache_server + if Travis::Features.feature_active?(:use_rack_cache) && memcache_servers use Rack::Cache, verbose: true, metastore: "memcached://#{memcache_servers}/#{Travis::Api::App.deploy_sha}", From d1a6ff7b49dd1b7a176c88ae76e832e1f1e7197a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 2 Sep 2013 13:41:13 +0200 Subject: [PATCH 062/185] Use MEMCACHIER_SERVERS --- lib/travis/api/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 8ae5f30b..62f82265 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -85,7 +85,7 @@ module Travis::Api use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache - memcache_servers = ENV['MEMCACHE_SERVERS'] + memcache_servers = ENV['MEMCACHIER_SERVERS'] if Travis::Features.feature_active?(:use_rack_cache) && memcache_servers use Rack::Cache, verbose: true, From 85275895e7b61b22309dd965a77b69538d310b7c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 2 Sep 2013 13:43:14 +0200 Subject: [PATCH 063/185] Require dalli before rack/cache --- lib/travis/api/app.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 62f82265..4bda5f5b 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -3,6 +3,7 @@ require 'backports' require 'rack' require 'rack/protection' require 'rack/contrib' +require 'dalli' require 'rack/cache' require 'rack/attack' require 'active_record' @@ -89,8 +90,8 @@ module Travis::Api if Travis::Features.feature_active?(:use_rack_cache) && memcache_servers use Rack::Cache, verbose: true, - metastore: "memcached://#{memcache_servers}/#{Travis::Api::App.deploy_sha}", - entitystore: "memcached://#{memcache_servers}/#{Travis::Api::App.deploy_sha}" + metastore: "memcached://#{memcache_servers}/meta-#{Travis::Api::App.deploy_sha}", + entitystore: "memcached://#{memcache_servers}/body-#{Travis::Api::App.deploy_sha}" end use Rack::Deflater From dae72e62a820a1475e60a246b2b4cdd8b413c41e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 2 Sep 2013 13:46:32 +0200 Subject: [PATCH 064/185] Use memcachier gem --- Gemfile | 1 + Gemfile.lock | 2 ++ lib/travis/api/app.rb | 1 + 3 files changed, 4 insertions(+) diff --git a/Gemfile b/Gemfile index 77295f28..3bd4a90d 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ gem 'rack-attack' gem 'gh' gem 'bunny', '~> 0.8.0' gem 'dalli' +gem 'memcachier' gem 'pry' gem 'metriks', '0.9.9.5' diff --git a/Gemfile.lock b/Gemfile.lock index fe2abf3f..04b4c59b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -167,6 +167,7 @@ GEM mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) + memcachier (0.0.2) metaclass (0.0.1) method_source (0.8.1) metriks (0.9.9.5) @@ -288,6 +289,7 @@ DEPENDENCIES factory_girl (~> 2.4.0) foreman gh + memcachier metriks (= 0.9.9.5) micro_migrations! mocha (~> 0.12) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 4bda5f5b..0815f606 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -4,6 +4,7 @@ require 'rack' require 'rack/protection' require 'rack/contrib' require 'dalli' +require 'memcachier' require 'rack/cache' require 'rack/attack' require 'active_record' From dae80733f9f3359d703ec4e9643829e7e2297177 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 3 Sep 2013 13:53:32 +0200 Subject: [PATCH 065/185] Test on ruby 2.0.0 --- .travis.yml | 2 +- Gemfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9c38f8c1..ccb43d2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rvm: - - 1.9.3 + - 2.0.0 before_script: - 'RAILS_ENV=test rake db:create db:schema:load --trace' notifications: diff --git a/Gemfile b/Gemfile index 3bd4a90d..cbe7b999 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -ruby '1.9.3' rescue nil +ruby '2.0.0' rescue nil source 'https://rubygems.org' gemspec From abce9844d7442c7eca339e90f77e912c6ea7eaf5 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 3 Sep 2013 14:03:55 +0200 Subject: [PATCH 066/185] Update octopus --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 04b4c59b..3973e5ea 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,11 +23,11 @@ GIT GIT remote: git://github.com/travis-ci/octopus.git - revision: 2d4cca475479516f47c3144971205f50c335ad35 + revision: 6e68a6c112df4de4a8495a1058be3d7cdd7f9f3d specs: - ar-octopus (0.5.0beta) - activerecord (>= 2.3.0) - activesupport (>= 2.3.0) + ar-octopus (0.6.0) + activerecord (>= 3.0.0, < 4.0) + activesupport (>= 3.0.0, < 4.0) GIT remote: git://github.com/travis-ci/travis-core.git From 24577ab03a6f3ce7f1493172ffe35d20b95421cd Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 3 Sep 2013 14:13:17 +0200 Subject: [PATCH 067/185] Don't load Travis::Helpers::Legacy --- config.ru | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.ru b/config.ru index ad88e886..1a0d6ad3 100644 --- a/config.ru +++ b/config.ru @@ -9,7 +9,7 @@ require 'core_ext/module/load_constants' models = Travis::Model.constants.map(&:to_s) only = [/^(ActiveRecord|ActiveModel|Travis|GH|#{models.join('|')})/] -skip = ['Travis::Memory', 'GH::ResponseWrapper', 'Travis::NewRelic'] +skip = ['Travis::Memory', 'GH::ResponseWrapper', 'Travis::NewRelic', 'Travis::Helpers::Legacy'] [Travis::Api, Travis, GH].each do |target| target.load_constants! :only => only, :skip => skip, :debug => false From 10b17e6e062f020ae60ff2c38ce419ee43fa3668 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 3 Sep 2013 14:37:26 +0200 Subject: [PATCH 068/185] Bump travis-core --- Gemfile.lock | 6 +++--- config.ru | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3973e5ea..7c95430b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,7 +31,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 0b939751455e48fdfbe4618898774030a9bed839 + revision: d974636561d51842b53c9430b6732edcb0939c22 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -145,7 +145,7 @@ GEM foreman (0.63.0) dotenv (>= 0.7) thor (>= 0.13.6) - gh (0.11.3) + gh (0.12.2) addressable backports faraday (~> 0.8) @@ -174,7 +174,7 @@ GEM atomic (~> 1.0) avl_tree (~> 1.1.2) hitimes (~> 1.1) - mime-types (1.24) + mime-types (1.25) mocha (0.14.0) metaclass (~> 0.0.1) multi_json (1.7.9) diff --git a/config.ru b/config.ru index 1a0d6ad3..e0be66b1 100644 --- a/config.ru +++ b/config.ru @@ -9,7 +9,7 @@ require 'core_ext/module/load_constants' models = Travis::Model.constants.map(&:to_s) only = [/^(ActiveRecord|ActiveModel|Travis|GH|#{models.join('|')})/] -skip = ['Travis::Memory', 'GH::ResponseWrapper', 'Travis::NewRelic', 'Travis::Helpers::Legacy'] +skip = ['Travis::Memory', 'GH::ResponseWrapper', 'Travis::NewRelic', 'Travis::Helpers::Legacy', 'GH::FaradayAdapter::EMSynchrony'] [Travis::Api, Travis, GH].each do |target| target.load_constants! :only => only, :skip => skip, :debug => false From d13352889305c2719ad50f3c0d8427beacebe91d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 3 Sep 2013 14:45:12 +0200 Subject: [PATCH 069/185] Use follower for /builds and /jobs --- lib/travis/api/app/endpoint/builds.rb | 8 +++++--- lib/travis/api/app/endpoint/jobs.rb | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index 3e48cf16..e5b3e076 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -4,9 +4,11 @@ class Travis::Api::App class Endpoint class Builds < Endpoint get '/' do - name = params[:branches] ? :find_branches : :find_builds - params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split) - respond_with service(name, params) + prefer_follower do + name = params[:branches] ? :find_branches : :find_builds + params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split) + respond_with service(name, params) + end end get '/:id' do diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 262d5396..1af3b8b1 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -4,7 +4,9 @@ class Travis::Api::App class Endpoint class Jobs < Endpoint get '/' do - respond_with service(:find_jobs, params) + prefer_follower do + respond_with service(:find_jobs, params) + end end get '/:id' do From dcc65cc735916ded7f41c1050ca04ed4de85c803 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 3 Sep 2013 17:26:20 +0200 Subject: [PATCH 070/185] Use ruby 1.9.3 --- .travis.yml | 2 +- Gemfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ccb43d2d..9c38f8c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rvm: - - 2.0.0 + - 1.9.3 before_script: - 'RAILS_ENV=test rake db:create db:schema:load --trace' notifications: diff --git a/Gemfile b/Gemfile index cbe7b999..3bd4a90d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -ruby '2.0.0' rescue nil +ruby '1.9.3' rescue nil source 'https://rubygems.org' gemspec From fd41e9ca1c1839e252d47b371d544d43a1d17fad Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 4 Sep 2013 13:31:02 +0200 Subject: [PATCH 071/185] Bump travis-core --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7c95430b..a2c54da6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,7 +31,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: d974636561d51842b53c9430b6732edcb0939c22 + revision: f9955cb522233dbcbe218717634618002b7e5bd0 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -145,7 +145,7 @@ GEM foreman (0.63.0) dotenv (>= 0.7) thor (>= 0.13.6) - gh (0.12.2) + gh (0.12.4) addressable backports faraday (~> 0.8) From 130eaa7c3d5dee99ff97c95f54ed4e62e279c5a8 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 4 Sep 2013 14:24:46 +0200 Subject: [PATCH 072/185] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index a2c54da6..bdc43cc9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,7 +31,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: f9955cb522233dbcbe218717634618002b7e5bd0 + revision: f3c2b689fd8ff1986501259f270eba2bc705a9ad specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 2492d710e14a4c22491caf8ef61daaad364e9009 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 4 Sep 2013 16:22:32 +0200 Subject: [PATCH 073/185] Use new follower API added to Travis::Model --- Gemfile | 2 -- Gemfile.lock | 9 --------- lib/travis/api/app.rb | 22 ++-------------------- lib/travis/api/app/helpers/db_follower.rb | 4 ++-- 4 files changed, 4 insertions(+), 33 deletions(-) diff --git a/Gemfile b/Gemfile index 3bd4a90d..c4d597df 100644 --- a/Gemfile +++ b/Gemfile @@ -22,8 +22,6 @@ gem 'memcachier' gem 'pry' gem 'metriks', '0.9.9.5' -gem 'ar-octopus', github: 'travis-ci/octopus', require: nil - group :test do gem 'rspec', '~> 2.13' gem 'factory_girl', '~> 2.4.0' diff --git a/Gemfile.lock b/Gemfile.lock index bdc43cc9..138484c7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -21,14 +21,6 @@ GIT yard-sinatra (1.0.0) yard (~> 0.7) -GIT - remote: git://github.com/travis-ci/octopus.git - revision: 6e68a6c112df4de4a8495a1058be3d7cdd7f9f3d - specs: - ar-octopus (0.6.0) - activerecord (>= 3.0.0, < 4.0) - activesupport (>= 3.0.0, < 4.0) - GIT remote: git://github.com/travis-ci/travis-core.git revision: f3c2b689fd8ff1986501259f270eba2bc705a9ad @@ -282,7 +274,6 @@ PLATFORMS ruby DEPENDENCIES - ar-octopus! bunny (~> 0.8.0) dalli database_cleaner (~> 0.8.0) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 0815f606..354fc753 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -159,26 +159,8 @@ module Travis::Api def self.setup_database_connections Travis::Database.connect - - return unless Travis.config.use_database_follower? - require 'octopus' - - if Travis.env == 'production' || Travis.env == 'staging' - puts "Setting up the DB follower as a read slave" - - # Octopus checks for Rails.env, just hardcode enabled? - Octopus.instance_eval do - def enabled? - true - end - end - - ActiveRecord::Base.custom_octopus_connection = false - - ::Octopus.setup do |config| - config.shards = { :follower => Travis.config.database_follower } - config.environments = ['production', 'staging'] - end + if Travis.config.database_follower + Travis::Model.establish_follower_connection(Travis.config.database_follower) end end diff --git a/lib/travis/api/app/helpers/db_follower.rb b/lib/travis/api/app/helpers/db_follower.rb index 1bd654e4..948f70c5 100644 --- a/lib/travis/api/app/helpers/db_follower.rb +++ b/lib/travis/api/app/helpers/db_follower.rb @@ -4,8 +4,8 @@ class Travis::Api::App module Helpers module DbFollower def prefer_follower - if Travis.config.use_database_follower? - Octopus.using(:follower) do + if Travis::Features.feature_active?(:api_use_db_follower) + Travis::Model.using_follower do yield end else From 59cd6bac8fcc9bced2886246fa11de38e9419f14 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 4 Sep 2013 20:31:36 +0200 Subject: [PATCH 074/185] We don't need Rack::Deflater, nginx is doing the job --- lib/travis/api/app.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 354fc753..1df37684 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -95,7 +95,6 @@ module Travis::Api entitystore: "memcached://#{memcache_servers}/body-#{Travis::Api::App.deploy_sha}" end - use Rack::Deflater use Rack::PostBodyContentTypeParser use Rack::JSONP From b484a19f27401688ee00ec8504fba746337f17c9 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 4 Sep 2013 20:32:30 +0200 Subject: [PATCH 075/185] Prefer follower also for /repos/id and repos list --- lib/travis/api/app/endpoint/repos.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/app/endpoint/repos.rb b/lib/travis/api/app/endpoint/repos.rb index 34179b36..1d502abf 100644 --- a/lib/travis/api/app/endpoint/repos.rb +++ b/lib/travis/api/app/endpoint/repos.rb @@ -13,7 +13,9 @@ class Travis::Api::App # # json(:repositories) get '/' do - respond_with service(:find_repos, params) + prefer_follower do + respond_with service(:find_repos, params) + end end # Gets the repository with the given id. @@ -22,7 +24,9 @@ class Travis::Api::App # # json(:repository) get '/:id' do - respond_with service(:find_repo, params) + prefer_follower do + respond_with service(:find_repo, params) + end end get '/:id/cc' do From fc132845913f3eb29de928b0f6930e6642a43ecc Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 4 Sep 2013 21:39:41 +0200 Subject: [PATCH 076/185] Revert "We don't need Rack::Deflater, nginx is doing the job" This reverts commit 59cd6bac8fcc9bced2886246fa11de38e9419f14. --- lib/travis/api/app.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 1df37684..354fc753 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -95,6 +95,7 @@ module Travis::Api entitystore: "memcached://#{memcache_servers}/body-#{Travis::Api::App.deploy_sha}" end + use Rack::Deflater use Rack::PostBodyContentTypeParser use Rack::JSONP From e587ef0b7f7a0768f89f4aabc7cff775f73576f3 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 5 Sep 2013 16:19:58 +0200 Subject: [PATCH 077/185] Add nginx config with CORS support --- config/nginx.conf.erb | 64 ++++++++++++++++++++++++++++++++++++++ lib/travis/api/app.rb | 2 -- lib/travis/api/app/cors.rb | 20 ------------ spec/unit/cors_spec.rb | 50 ----------------------------- 4 files changed, 64 insertions(+), 72 deletions(-) create mode 100644 config/nginx.conf.erb delete mode 100644 lib/travis/api/app/cors.rb delete mode 100644 spec/unit/cors_spec.rb diff --git a/config/nginx.conf.erb b/config/nginx.conf.erb new file mode 100644 index 00000000..2e0a0142 --- /dev/null +++ b/config/nginx.conf.erb @@ -0,0 +1,64 @@ +daemon off; +#Heroku dynos have 4 cores. +worker_processes 4; + +events { + use epoll; + accept_mutex on; + worker_connections 1024; +} + +http { + gzip on; + gzip_comp_level 2; + gzip_min_length 512; + + log_format l2met 'measure.nginx.service=$request_time request_id=$http_heroku_request_id'; + access_log logs/nginx/access.log l2met; + error_log logs/nginx/error.log; + + include mime.types; + default_type application/octet-stream; + sendfile on; + + #Must read the body in 5 seconds. + client_body_timeout 5; + + upstream app_server { + server unix:/tmp/nginx.socket fail_timeout=0; + } + + server { + listen <%= ENV["PORT"] %>; + server_name _; + keepalive_timeout 5; + + location / { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Credentials' 'true'; + add_header 'Access-Control-Expose-Headers' 'Content-Type, Cache-Control, Expires, Etag, Last-Modified'; + + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Credentials' 'true'; + add_header 'Access-Control-Expose-Headers' 'Content-Type, Cache-Control, Expires, Etag, Last-Modified'; + + # Tell browser to cache this pre-flight info for 20 days + add_header 'Access-Control-Max-Age' 1728000; + + add_header 'Access-Control-Allow-Methods' 'HEAD, GET, POST, PATCH, PUT, DELETE, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, Accept, If-None-Match, If-Modified-Since'; + + add_header 'Content-Length' 0; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + + return 204; + } + + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://app_server; + } + } +} diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 354fc753..774ae840 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -31,7 +31,6 @@ module Travis::Api autoload :Helpers, 'travis/api/app/helpers' autoload :Middleware, 'travis/api/app/middleware' autoload :Responders, 'travis/api/app/responders' - autoload :Cors, 'travis/api/app/cors' Rack.autoload :SSL, 'rack/ssl' @@ -80,7 +79,6 @@ module Travis::Api [ 420, {}, ['Enhance Your Calm']] end - use Travis::Api::App::Cors use Raven::Rack if Endpoint.production? use Rack::Protection::PathTraversal use Rack::SSL if Endpoint.production? diff --git a/lib/travis/api/app/cors.rb b/lib/travis/api/app/cors.rb deleted file mode 100644 index 781efc00..00000000 --- a/lib/travis/api/app/cors.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'travis/api/app' - -class Travis::Api::App - # Implements Cross-Origin Resource Sharing. Supported by all major browsers. - # See http://www.w3.org/TR/cors/ - # - # TODO: Be smarter about origin. - class Cors < Base - before do - headers['Access-Control-Allow-Origin'] = "*" - headers['Access-Control-Allow-Credentials'] = "true" - headers['Access-Control-Expose-Headers'] = "Content-Type, Cache-Control, Expires, Etag, Last-Modified" - end - - options // do - headers['Access-Control-Allow-Methods'] = "HEAD, GET, POST, PATCH, PUT, DELETE" - headers['Access-Control-Allow-Headers'] = "Content-Type, Authorization, Accept, If-None-Match, If-Modified-Since" - end - end -end diff --git a/spec/unit/cors_spec.rb b/spec/unit/cors_spec.rb deleted file mode 100644 index 83e79914..00000000 --- a/spec/unit/cors_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'spec_helper' - -describe Travis::Api::App::Cors do - before do - mock_app do - use Travis::Api::App::Cors - get('/check_cors') { 'ok' } - end - end - - describe 'normal request' do - before { get('/check_cors').should be_ok } - - it 'sets Access-Control-Allow-Origin' do - headers['Access-Control-Allow-Origin'].should == "*" - end - - it 'sets Access-Control-Allow-Credentials' do - headers['Access-Control-Allow-Credentials'].should == "true" - end - - it 'sets Access-Control-Expose-Headers' do - headers['Access-Control-Expose-Headers'].should == "Content-Type, Cache-Control, Expires, Etag, Last-Modified" - end - end - - describe 'OPTIONS requests' do - before { options('/').should be_ok } - - it 'sets Access-Control-Allow-Origin' do - headers['Access-Control-Allow-Origin'].should == "*" - end - - it 'sets Access-Control-Allow-Credentials' do - headers['Access-Control-Allow-Credentials'].should == "true" - end - - it 'sets Access-Control-Expose-Headers' do - headers['Access-Control-Expose-Headers'].should == "Content-Type, Cache-Control, Expires, Etag, Last-Modified" - end - - it 'sets Access-Control-Allow-Methods' do - headers['Access-Control-Allow-Methods'].should == "HEAD, GET, POST, PATCH, PUT, DELETE" - end - - it 'sets Access-Control-Allow-Headers' do - headers['Access-Control-Allow-Headers'].should == "Content-Type, Authorization, Accept, If-None-Match, If-Modified-Since" - end - end -end From 212ecc912e681c533ae30c652a4930d49ea652ed Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Fri, 6 Sep 2013 13:53:19 +0200 Subject: [PATCH 078/185] try some ruby gc tweaking --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 9c38f8c1..7917efa5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,8 @@ language: ruby +env: + global: + - RUBY_GC_MALLOC_LIMIT=90000000 + - RUBY_FREE_MIN=200000 rvm: - 1.9.3 before_script: From 1a3ab7f2a7fc1e4573c8be6b4df56a2f55d80d2b Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 6 Sep 2013 19:48:55 +0200 Subject: [PATCH 079/185] Always use follower if it's available --- lib/travis/api/app/helpers/db_follower.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/helpers/db_follower.rb b/lib/travis/api/app/helpers/db_follower.rb index 948f70c5..e4646e58 100644 --- a/lib/travis/api/app/helpers/db_follower.rb +++ b/lib/travis/api/app/helpers/db_follower.rb @@ -4,7 +4,7 @@ class Travis::Api::App module Helpers module DbFollower def prefer_follower - if Travis::Features.feature_active?(:api_use_db_follower) + if Travis.config.database_follower Travis::Model.using_follower do yield end From b391859dab404589c9d5fa629a114633a024a967 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 9 Sep 2013 18:20:26 +0200 Subject: [PATCH 080/185] Bump travis-core --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 138484c7..cbf3fddc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: f3c2b689fd8ff1986501259f270eba2bc705a9ad + revision: 53a73cb568c9290a9b9a4ea39170ce6ca4cb1133 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -137,7 +137,7 @@ GEM foreman (0.63.0) dotenv (>= 0.7) thor (>= 0.13.6) - gh (0.12.4) + gh (0.13.0) addressable backports faraday (~> 0.8) @@ -169,7 +169,7 @@ GEM mime-types (1.25) mocha (0.14.0) metaclass (~> 0.0.1) - multi_json (1.7.9) + multi_json (1.8.0) multipart-post (1.2.0) net-http-persistent (2.9) net-http-pipeline (1.0.1) From eef50cd537ee3ea1eff5ad25e57569c4ee8846b9 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 10 Sep 2013 00:59:06 +0200 Subject: [PATCH 081/185] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index cbf3fddc..d55dc91c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 53a73cb568c9290a9b9a4ea39170ce6ca4cb1133 + revision: b389c10d2429fb8799432c1efb8407adea62be81 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 783d197e7e865ed900f8caa5edc9d790b62652a5 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 10 Sep 2013 11:56:59 +0200 Subject: [PATCH 082/185] Tune GC for unicorn --- config/unicorn.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config/unicorn.rb b/config/unicorn.rb index be3065d1..1e9da525 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -9,3 +9,11 @@ require 'fileutils' before_fork do |server,worker| FileUtils.touch('/tmp/app-initialized') end + +before_exec do |server| + ENV['RUBY_HEAP_MIN_SLOTS']=800000 + ENV['RUBY_GC_MALLOC_LIMIT']=59000000 + ENV['RUBY_HEAP_SLOTS_INCREMENT']=10000 + ENV['RUBY_HEAP_SLOTS_GROWTH_FACTOR']=1 + ENV['RUBY_HEAP_FREE_MIN']=100000 +end From a49265f872a59088fd7d2d66fea3490a5d50fe67 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 10 Sep 2013 12:05:18 +0200 Subject: [PATCH 083/185] Disable follower for now --- lib/travis/api/app.rb | 3 --- lib/travis/api/app/helpers/db_follower.rb | 8 +------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 774ae840..7cfdc659 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -157,9 +157,6 @@ module Travis::Api def self.setup_database_connections Travis::Database.connect - if Travis.config.database_follower - Travis::Model.establish_follower_connection(Travis.config.database_follower) - end end def self.load_endpoints diff --git a/lib/travis/api/app/helpers/db_follower.rb b/lib/travis/api/app/helpers/db_follower.rb index e4646e58..a8642e4b 100644 --- a/lib/travis/api/app/helpers/db_follower.rb +++ b/lib/travis/api/app/helpers/db_follower.rb @@ -4,13 +4,7 @@ class Travis::Api::App module Helpers module DbFollower def prefer_follower - if Travis.config.database_follower - Travis::Model.using_follower do - yield - end - else - yield - end + yield end end end From 30a4abb8e8d758f11c0f52e81e99c0184694c3be Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 10 Sep 2013 12:41:21 +0200 Subject: [PATCH 084/185] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index d55dc91c..d693beda 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: b389c10d2429fb8799432c1efb8407adea62be81 + revision: 2d57f6bdd87c0d4c61e56c35b3b5d4ebaa4bf4cd specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 02c0efda5dc909b73f3bc725beb702409397eb2e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 10 Sep 2013 13:18:14 +0200 Subject: [PATCH 085/185] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index d693beda..38b86e8c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 2d57f6bdd87c0d4c61e56c35b3b5d4ebaa4bf4cd + revision: 098da5421df8cb7a237ca31fe86c91f3b2692c46 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From f97dfa984f07bd578b77bc4fe5a6d95bb3bd4dab Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 11 Sep 2013 11:27:26 +0200 Subject: [PATCH 086/185] Add memcachier to gemspec --- Gemfile | 1 - Gemfile.lock | 4 ++-- travis-api.gemspec | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index c4d597df..d45932fd 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,6 @@ gem 'rack-attack' gem 'gh' gem 'bunny', '~> 0.8.0' gem 'dalli' -gem 'memcachier' gem 'pry' gem 'metriks', '0.9.9.5' diff --git a/Gemfile.lock b/Gemfile.lock index 38b86e8c..5970cdcb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,6 +67,7 @@ PATH specs: travis-api (0.0.1) backports (~> 2.5) + memcachier newrelic_rpm (~> 3.6.6) pg (~> 0.13.2) rack-contrib (~> 1.1) @@ -173,7 +174,7 @@ GEM multipart-post (1.2.0) net-http-persistent (2.9) net-http-pipeline (1.0.1) - newrelic_rpm (3.6.6.147) + newrelic_rpm (3.6.7.152) pg (0.13.2) polyglot (0.3.3) pry (0.9.12.2) @@ -280,7 +281,6 @@ DEPENDENCIES factory_girl (~> 2.4.0) foreman gh - memcachier metriks (= 0.9.9.5) micro_migrations! mocha (~> 0.12) diff --git a/travis-api.gemspec b/travis-api.gemspec index d6d027fe..810b381e 100644 --- a/travis-api.gemspec +++ b/travis-api.gemspec @@ -206,5 +206,6 @@ Gem::Specification.new do |s| s.add_dependency 'redcarpet', '~> 2.1' s.add_dependency 'rack-ssl', '~> 1.3', '>= 1.3.3' s.add_dependency 'rack-contrib', '~> 1.1' + s.add_dependency 'memcachier' end From e6d1d5c494f7cd444bb6daa5528933d68f895d63 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 11 Sep 2013 17:21:13 +0200 Subject: [PATCH 087/185] Bump travis-core --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5970cdcb..966bbafb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 098da5421df8cb7a237ca31fe86c91f3b2692c46 + revision: c07b32d35baf124bec1bf2e572ff9b5aea1ddc9c specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -108,7 +108,7 @@ GEM multi_json (~> 1.0) addressable (2.3.5) arel (3.0.2) - atomic (1.1.13) + atomic (1.1.14) avl_tree (1.1.3) backports (2.8.2) builder (3.0.4) From d48c47bcfc402e9c81caec8e73cd048b0cb68af7 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 12 Sep 2013 12:13:58 +0200 Subject: [PATCH 088/185] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 966bbafb..042583b3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: c07b32d35baf124bec1bf2e572ff9b5aea1ddc9c + revision: 3a45afb991fecb3dea594c01502d27a1551b5417 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 8d1a3b2bea65e0d1ad1f97e3979320472dc1d2fd Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 12 Sep 2013 13:52:32 +0200 Subject: [PATCH 089/185] Bump travis-core (repos?member=:member fix) --- Gemfile.lock | 2 +- spec/unit/endpoint/users_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 042583b3..f617921d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 3a45afb991fecb3dea594c01502d27a1551b5417 + revision: a02b830498e64dff77b3ed99d7b9f53b546014df specs: travis-core (0.0.1) actionmailer (~> 3.2.12) diff --git a/spec/unit/endpoint/users_spec.rb b/spec/unit/endpoint/users_spec.rb index 8edee8bf..7675b170 100644 --- a/spec/unit/endpoint/users_spec.rb +++ b/spec/unit/endpoint/users_spec.rb @@ -24,6 +24,7 @@ describe Travis::Api::App::Endpoint::Users do 'gravatar_id' => user.gravatar_id, 'locale' => user.locale, 'is_syncing' => user.is_syncing, + 'created_at' => user.created_at.strftime('%Y-%m-%dT%H:%M:%SZ'), 'synced_at' => user.synced_at.strftime('%Y-%m-%dT%H:%M:%SZ'), 'correct_scopes' => true, } From 4e7bf3fe78ed6a8cea85e5f20a068a6399ffa47f Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 14 Sep 2013 00:59:42 +0200 Subject: [PATCH 090/185] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index f617921d..0f2e803c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: a02b830498e64dff77b3ed99d7b9f53b546014df + revision: db3e01e76bb697b62fbd21e22b4426a5cbd97d0e specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From d6684dd44187ecb7268436e6bfb28f203e2840e5 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 16 Sep 2013 14:44:49 +0200 Subject: [PATCH 091/185] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0f2e803c..166f4bd1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: db3e01e76bb697b62fbd21e22b4426a5cbd97d0e + revision: cae4cfbfbbc6c24354a9b4360d021a10f95f4e64 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 0681e54cf1f72ad77ccdcc438f69635adc19128c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 20 Sep 2013 12:47:14 +0200 Subject: [PATCH 092/185] Run CORS middleware in development --- lib/travis/api/app.rb | 2 ++ lib/travis/api/app/cors.rb | 20 +++++++++++++++ spec/unit/cors_spec.rb | 50 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 lib/travis/api/app/cors.rb create mode 100644 spec/unit/cors_spec.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 7cfdc659..023ff2c7 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -31,6 +31,7 @@ module Travis::Api autoload :Helpers, 'travis/api/app/helpers' autoload :Middleware, 'travis/api/app/middleware' autoload :Responders, 'travis/api/app/responders' + autoload :Cors, 'travis/api/app/cors' Rack.autoload :SSL, 'rack/ssl' @@ -79,6 +80,7 @@ module Travis::Api [ 420, {}, ['Enhance Your Calm']] end + use Travis::Api::App::Cors unless Endpoint.production? use Raven::Rack if Endpoint.production? use Rack::Protection::PathTraversal use Rack::SSL if Endpoint.production? diff --git a/lib/travis/api/app/cors.rb b/lib/travis/api/app/cors.rb new file mode 100644 index 00000000..781efc00 --- /dev/null +++ b/lib/travis/api/app/cors.rb @@ -0,0 +1,20 @@ +require 'travis/api/app' + +class Travis::Api::App + # Implements Cross-Origin Resource Sharing. Supported by all major browsers. + # See http://www.w3.org/TR/cors/ + # + # TODO: Be smarter about origin. + class Cors < Base + before do + headers['Access-Control-Allow-Origin'] = "*" + headers['Access-Control-Allow-Credentials'] = "true" + headers['Access-Control-Expose-Headers'] = "Content-Type, Cache-Control, Expires, Etag, Last-Modified" + end + + options // do + headers['Access-Control-Allow-Methods'] = "HEAD, GET, POST, PATCH, PUT, DELETE" + headers['Access-Control-Allow-Headers'] = "Content-Type, Authorization, Accept, If-None-Match, If-Modified-Since" + end + end +end diff --git a/spec/unit/cors_spec.rb b/spec/unit/cors_spec.rb new file mode 100644 index 00000000..83e79914 --- /dev/null +++ b/spec/unit/cors_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe Travis::Api::App::Cors do + before do + mock_app do + use Travis::Api::App::Cors + get('/check_cors') { 'ok' } + end + end + + describe 'normal request' do + before { get('/check_cors').should be_ok } + + it 'sets Access-Control-Allow-Origin' do + headers['Access-Control-Allow-Origin'].should == "*" + end + + it 'sets Access-Control-Allow-Credentials' do + headers['Access-Control-Allow-Credentials'].should == "true" + end + + it 'sets Access-Control-Expose-Headers' do + headers['Access-Control-Expose-Headers'].should == "Content-Type, Cache-Control, Expires, Etag, Last-Modified" + end + end + + describe 'OPTIONS requests' do + before { options('/').should be_ok } + + it 'sets Access-Control-Allow-Origin' do + headers['Access-Control-Allow-Origin'].should == "*" + end + + it 'sets Access-Control-Allow-Credentials' do + headers['Access-Control-Allow-Credentials'].should == "true" + end + + it 'sets Access-Control-Expose-Headers' do + headers['Access-Control-Expose-Headers'].should == "Content-Type, Cache-Control, Expires, Etag, Last-Modified" + end + + it 'sets Access-Control-Allow-Methods' do + headers['Access-Control-Allow-Methods'].should == "HEAD, GET, POST, PATCH, PUT, DELETE" + end + + it 'sets Access-Control-Allow-Headers' do + headers['Access-Control-Allow-Headers'].should == "Content-Type, Authorization, Accept, If-None-Match, If-Modified-Since" + end + end +end From cbb99afe89c571f4c7e6fef43421d2abb6554f7c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 20 Sep 2013 13:59:43 +0200 Subject: [PATCH 093/185] Check for development rather than production to make it work on staging --- lib/travis/api/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 023ff2c7..86301e08 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -80,7 +80,7 @@ module Travis::Api [ 420, {}, ['Enhance Your Calm']] end - use Travis::Api::App::Cors unless Endpoint.production? + use Travis::Api::App::Cors if Travis.env == 'development' use Raven::Rack if Endpoint.production? use Rack::Protection::PathTraversal use Rack::SSL if Endpoint.production? From bb919bdf4219af6bacb903a6749d13eda242ad30 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 3 Oct 2013 16:24:21 +0200 Subject: [PATCH 094/185] update core --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 166f4bd1..9a418bf7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: cae4cfbfbbc6c24354a9b4360d021a10f95f4e64 + revision: a5009d186ba37171bbdedf52c19a9e812f7f39da specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -52,7 +52,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: 7c69fe727968b31551ce3acbe0d4f2e0e5bc8fa3 + revision: fffb09b3e6967cdb6c33f04ac7f7840a8df77400 specs: travis-support (0.0.1) From 93277035cd7b0dc5190226081f21ae24c5773ba2 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 3 Oct 2013 16:24:35 +0200 Subject: [PATCH 095/185] add repo endpoints for fetching branches --- lib/travis/api/app/endpoint/repos.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/travis/api/app/endpoint/repos.rb b/lib/travis/api/app/endpoint/repos.rb index 1d502abf..fd3bbd27 100644 --- a/lib/travis/api/app/endpoint/repos.rb +++ b/lib/travis/api/app/endpoint/repos.rb @@ -50,6 +50,16 @@ class Travis::Api::App respond_with service(:regenerate_repo_key, params), version: :v2 end + # Gets list of branches + get '/:id/branches' do + respond_with service(:find_branches, params), type: :branches, version: :v2 + end + + # Gets lastest build on a branch branches + get '/:id/branches/:branch' do + respond_with service(:find_branch, params), type: :branch, version: :v2 + end + # Gets the repository with the given name. # # ### Response @@ -101,6 +111,16 @@ class Travis::Api::App post '/:owner_name/:name/key' do respond_with service(:regenerate_repo_key, params), version: :v2 end + + # Gets list of branches + get '/:owner_name/:name/branches' do + respond_with service(:find_branches, params), type: :branches, version: :v2 + end + + # Gets lastest build on a branch branches + get '/:owner_name/:name/branches/:branch' do + respond_with service(:find_branch, params), type: :branch, version: :v2 + end end end end From 059e380e0b63e5bd7a933c9e2de1219d342c7356 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 3 Oct 2013 16:36:29 +0200 Subject: [PATCH 096/185] update travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9a418bf7..1f4b1d5e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: a5009d186ba37171bbdedf52c19a9e812f7f39da + revision: e46364c38f57ae08d66aa2e00b0e76104712e35c specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From 6f72b2cb6b18dbcad5132971a0ba2b65150c1769 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 3 Oct 2013 17:25:40 +0200 Subject: [PATCH 097/185] find_branch(es) expects parameter to be called repository_id --- lib/travis/api/app/endpoint/repos.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/app/endpoint/repos.rb b/lib/travis/api/app/endpoint/repos.rb index fd3bbd27..1f8b0e3b 100644 --- a/lib/travis/api/app/endpoint/repos.rb +++ b/lib/travis/api/app/endpoint/repos.rb @@ -51,12 +51,12 @@ class Travis::Api::App end # Gets list of branches - get '/:id/branches' do + get '/:repository_id/branches' do respond_with service(:find_branches, params), type: :branches, version: :v2 end # Gets lastest build on a branch branches - get '/:id/branches/:branch' do + get '/:repository_id/branches/:branch' do respond_with service(:find_branch, params), type: :branch, version: :v2 end From 8ccf48fa2ae8ced2dd239f45687ee9779cca5653 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sat, 5 Oct 2013 19:10:09 +0200 Subject: [PATCH 098/185] remove the log PUT endpoint, no longer needed --- lib/travis/api/app/endpoint/logs.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/travis/api/app/endpoint/logs.rb b/lib/travis/api/app/endpoint/logs.rb index 83692be5..082e91d4 100644 --- a/lib/travis/api/app/endpoint/logs.rb +++ b/lib/travis/api/app/endpoint/logs.rb @@ -8,14 +8,6 @@ class Travis::Api::App get '/:id' do |id| respond_with service(:find_log, params) end - - put '/:id' do |id| - # TODO @rkh ... rather lost in the auth/scopes code. - token = env['HTTP_TOKEN'] - halt 403, 'no token' unless token - halt 403, 'internal' unless token == Travis.config.tokens.internal - respond_with service(:update_log, params) - end end end end From 714fe3f61798d812ab7a56afc140bb32a1d371ef Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 13 Oct 2013 15:27:25 +0200 Subject: [PATCH 099/185] update bunny for ssl support --- Gemfile | 2 +- Gemfile.lock | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index d45932fd..38c188c4 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ gem 'rack-contrib', github: 'rack/rack-contrib' gem 'rack-cache', '~> 1.2' gem 'rack-attack' gem 'gh' -gem 'bunny', '~> 0.8.0' +gem 'bunny', '~> 0.10.8' gem 'dalli' gem 'pry' gem 'metriks', '0.9.9.5' diff --git a/Gemfile.lock b/Gemfile.lock index 1f4b1d5e..e7bd1e46 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,12 +107,14 @@ GEM i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) addressable (2.3.5) + amq-protocol (1.8.0) arel (3.0.2) atomic (1.1.14) avl_tree (1.1.3) backports (2.8.2) builder (3.0.4) - bunny (0.8.0) + bunny (0.10.8) + amq-protocol (>= 1.6.0) celluloid (0.12.4) facter (>= 1.6.12) timers (>= 1.0.0) @@ -275,7 +277,7 @@ PLATFORMS ruby DEPENDENCIES - bunny (~> 0.8.0) + bunny (~> 0.10.8) dalli database_cleaner (~> 0.8.0) factory_girl (~> 2.4.0) From fc600cc30b86781ef42c04f9ffec49597fdb95c6 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 13 Oct 2013 16:18:38 +0200 Subject: [PATCH 100/185] update travis-support for an amqp bunny config change --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index e7bd1e46..7ddd46fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,7 +52,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: fffb09b3e6967cdb6c33f04ac7f7840a8df77400 + revision: df798c71815d09c3422f29fd90ad4a73deec0f44 specs: travis-support (0.0.1) From e15e3747b782896b55ee0da02070f7b84e30fe0b Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 13 Oct 2013 17:43:03 +0200 Subject: [PATCH 101/185] try using bunny 1.0.0.rc2 --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 38c188c4..5690338f 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ gem 'rack-contrib', github: 'rack/rack-contrib' gem 'rack-cache', '~> 1.2' gem 'rack-attack' gem 'gh' -gem 'bunny', '~> 0.10.8' +gem 'bunny', '~> 1.0.0.rc2' gem 'dalli' gem 'pry' gem 'metriks', '0.9.9.5' diff --git a/Gemfile.lock b/Gemfile.lock index 7ddd46fe..09cf1966 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,8 +113,8 @@ GEM avl_tree (1.1.3) backports (2.8.2) builder (3.0.4) - bunny (0.10.8) - amq-protocol (>= 1.6.0) + bunny (1.0.0.rc2) + amq-protocol (>= 1.8.0) celluloid (0.12.4) facter (>= 1.6.12) timers (>= 1.0.0) @@ -277,7 +277,7 @@ PLATFORMS ruby DEPENDENCIES - bunny (~> 0.10.8) + bunny (~> 1.0.0.rc2) dalli database_cleaner (~> 0.8.0) factory_girl (~> 2.4.0) From 90c26dc111bb1310e97a4480bc9e4bb1015806de Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 13 Oct 2013 18:10:07 +0200 Subject: [PATCH 102/185] lets try 0.9.8 bunny --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 5690338f..449c454a 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ gem 'rack-contrib', github: 'rack/rack-contrib' gem 'rack-cache', '~> 1.2' gem 'rack-attack' gem 'gh' -gem 'bunny', '~> 1.0.0.rc2' +gem 'bunny', '~> 0.9.8' gem 'dalli' gem 'pry' gem 'metriks', '0.9.9.5' diff --git a/Gemfile.lock b/Gemfile.lock index 09cf1966..c9690673 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,8 +113,8 @@ GEM avl_tree (1.1.3) backports (2.8.2) builder (3.0.4) - bunny (1.0.0.rc2) - amq-protocol (>= 1.8.0) + bunny (0.9.8) + amq-protocol (>= 1.6.0) celluloid (0.12.4) facter (>= 1.6.12) timers (>= 1.0.0) @@ -277,7 +277,7 @@ PLATFORMS ruby DEPENDENCIES - bunny (~> 1.0.0.rc2) + bunny (~> 0.9.8) dalli database_cleaner (~> 0.8.0) factory_girl (~> 2.4.0) From ade4d4ad0116e7a6e77bdc36c89dad77b3e87b79 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 13 Oct 2013 18:16:01 +0200 Subject: [PATCH 103/185] back to bunny 0.8.x --- Gemfile | 2 +- Gemfile.lock | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 449c454a..d45932fd 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ gem 'rack-contrib', github: 'rack/rack-contrib' gem 'rack-cache', '~> 1.2' gem 'rack-attack' gem 'gh' -gem 'bunny', '~> 0.9.8' +gem 'bunny', '~> 0.8.0' gem 'dalli' gem 'pry' gem 'metriks', '0.9.9.5' diff --git a/Gemfile.lock b/Gemfile.lock index c9690673..4efcb15a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,14 +107,12 @@ GEM i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) addressable (2.3.5) - amq-protocol (1.8.0) arel (3.0.2) atomic (1.1.14) avl_tree (1.1.3) backports (2.8.2) builder (3.0.4) - bunny (0.9.8) - amq-protocol (>= 1.6.0) + bunny (0.8.0) celluloid (0.12.4) facter (>= 1.6.12) timers (>= 1.0.0) @@ -277,7 +275,7 @@ PLATFORMS ruby DEPENDENCIES - bunny (~> 0.9.8) + bunny (~> 0.8.0) dalli database_cleaner (~> 0.8.0) factory_girl (~> 2.4.0) From 096d08c102cbf8fc08274f27b7ec002be8bccac6 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 15 Oct 2013 12:24:07 +0200 Subject: [PATCH 104/185] add /repos/:owner_name, fixes travis-ci/travis-ci#1496 --- lib/travis/api/app/endpoint/repos.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/travis/api/app/endpoint/repos.rb b/lib/travis/api/app/endpoint/repos.rb index 1f8b0e3b..d6cf9f16 100644 --- a/lib/travis/api/app/endpoint/repos.rb +++ b/lib/travis/api/app/endpoint/repos.rb @@ -18,6 +18,14 @@ class Travis::Api::App end end + # Retrieves repositories for a given owner. + get '/:owner_name' do + pass if params[:owner_name] =~ /^\d+$/ # so we don't capture '/:id' + prefer_follower do + respond_with service(:find_repos, params) + end + end + # Gets the repository with the given id. # # ### Response From 0ebbef709480e376d8339c231a999796b317511d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 15 Oct 2013 14:07:58 +0200 Subject: [PATCH 105/185] Bump travis-core (cancel build amqp fix) --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4efcb15a..d789b467 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: e46364c38f57ae08d66aa2e00b0e76104712e35c + revision: f1b763875c5b6008b3fad1af90ff7fbe460f9ee9 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -170,7 +170,7 @@ GEM mime-types (1.25) mocha (0.14.0) metaclass (~> 0.0.1) - multi_json (1.8.0) + multi_json (1.8.2) multipart-post (1.2.0) net-http-persistent (2.9) net-http-pipeline (1.0.1) @@ -212,7 +212,7 @@ GEM rdoc (3.12.2) json (~> 1.4) redcarpet (2.3.0) - redis (3.0.4) + redis (3.0.5) redis-namespace (1.3.0) redis (~> 3.0.0) rerun (0.8.1) @@ -263,7 +263,7 @@ GEM treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.37) + tzinfo (0.3.38) unicorn (4.6.3) kgio (~> 2.6) rack From 0cdfa8240c68aff17e8077b71cca6bc038c7f042 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 16 Oct 2013 17:39:31 +0200 Subject: [PATCH 106/185] Add source to cancel_build/job --- lib/travis/api/app/endpoint/builds.rb | 2 +- lib/travis/api/app/endpoint/jobs.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index e5b3e076..64e4e684 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -18,7 +18,7 @@ class Travis::Api::App post '/:id/cancel' do Metriks.meter("api.request.cancel_build").mark - service = self.service(:cancel_build, params) + service = self.service(:cancel_build, params.merge(source: 'api')) if !service.authorized? json = { error: { message: "You don't have access to cancel build(#{params[:id]})" diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 1af3b8b1..513fb888 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -42,7 +42,7 @@ class Travis::Api::App post '/:id/cancel' do Metriks.meter("api.request.cancel_job").mark - service = self.service(:cancel_job, params) + service = self.service(:cancel_job, params.merge(source: 'api')) if !service.authorized? json = { error: { message: "You don't have access to cancel job(#{params[:id]})" From cd446eadd06540c18e805fe726d4d14004deb49c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 16 Oct 2013 18:03:09 +0200 Subject: [PATCH 107/185] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index d789b467..d496a9fb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: f1b763875c5b6008b3fad1af90ff7fbe460f9ee9 + revision: bcc14ad2fafff932f1b681a332b6435b50ddb099 specs: travis-core (0.0.1) actionmailer (~> 3.2.12) From ac9b31336a8f1d5f4f418889a12cf10d30798596 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 17 Oct 2013 14:36:03 +0200 Subject: [PATCH 108/185] Bump travis-support --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index d496a9fb..3a1cce3e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,7 +52,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: df798c71815d09c3422f29fd90ad4a73deec0f44 + revision: f6d8589412dbdf6dae18a5a928c8a8de229ca65a specs: travis-support (0.0.1) From e35b7a3301d820689da6ec19417fb8bc2644f6fe Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 17 Oct 2013 14:45:42 +0200 Subject: [PATCH 109/185] Bump travis-support --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3a1cce3e..86931215 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,7 +52,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: f6d8589412dbdf6dae18a5a928c8a8de229ca65a + revision: e5294f7d1f04243ea7315de27c36f2feeccec5da specs: travis-support (0.0.1) From 8f4dd0d2df63e7c72b394533f0646ca7998f1f7e Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 23 Oct 2013 19:35:03 -0500 Subject: [PATCH 110/185] Respond with 422 if /auth/github does not get a token Fix #77 --- lib/travis/api/app/endpoint/authorization.rb | 4 ++++ spec/unit/endpoint/authorization_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/travis/api/app/endpoint/authorization.rb b/lib/travis/api/app/endpoint/authorization.rb index 8bc2f296..85c64079 100644 --- a/lib/travis/api/app/endpoint/authorization.rb +++ b/lib/travis/api/app/endpoint/authorization.rb @@ -78,6 +78,10 @@ class Travis::Api::App # # * **github_token**: GitHub token for checking authorization (required) post '/github' do + unless params[:github_token] + halt 422, { "error" => "Must pass 'github_token' parameter" } + end + { 'access_token' => github_to_travis(params[:github_token], app_id: 1, drop_token: true) } end diff --git a/spec/unit/endpoint/authorization_spec.rb b/spec/unit/endpoint/authorization_spec.rb index 7f1727f9..12f8529c 100644 --- a/spec/unit/endpoint/authorization_spec.rb +++ b/spec/unit/endpoint/authorization_spec.rb @@ -64,5 +64,11 @@ describe Travis::Api::App::Endpoint::Authorization do it 'does not store the token' do user_for('public repos').github_oauth_token.should_not == 'public repos' end + + it "errors if no token is given" do + post("/auth/github").should_not be_ok + last_response.status.should == 422 + body.should_not include("access_token") + end end end From 44f274d30664a47298b4bf8ccfd625ea82c2647b Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Sat, 26 Oct 2013 08:14:40 -0500 Subject: [PATCH 111/185] Only allow XML response if repo has a build --- lib/travis/api/app/responders/xml.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/responders/xml.rb b/lib/travis/api/app/responders/xml.rb index 836d5f20..423fca46 100644 --- a/lib/travis/api/app/responders/xml.rb +++ b/lib/travis/api/app/responders/xml.rb @@ -16,7 +16,7 @@ module Travis::Api::App::Responders } def apply? - super && resource.is_a?(Repository) + super && resource.is_a?(Repository) && last_build end def apply From 65267795f1193aad9a07b0bc650f64fb58408dfc Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Sat, 26 Oct 2013 08:19:01 -0500 Subject: [PATCH 112/185] Only allow image responses for repositories --- lib/travis/api/app/responders/image.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/travis/api/app/responders/image.rb b/lib/travis/api/app/responders/image.rb index c6c6a17d..44a37faa 100644 --- a/lib/travis/api/app/responders/image.rb +++ b/lib/travis/api/app/responders/image.rb @@ -11,6 +11,10 @@ module Travis::Api::App::Responders send_file(filename, type: :png, last_modified: last_modified) end + def apply? + super && resource.is_a?(Repository) + end + private def content_type From c64a006f1d1b96807fbc847da079ad9e04eca749 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Sat, 26 Oct 2013 08:33:57 -0500 Subject: [PATCH 113/185] Handle race condition with creating users more nicely --- lib/travis/api/app/endpoint/authorization.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/travis/api/app/endpoint/authorization.rb b/lib/travis/api/app/endpoint/authorization.rb index 85c64079..80a05363 100644 --- a/lib/travis/api/app/endpoint/authorization.rb +++ b/lib/travis/api/app/endpoint/authorization.rb @@ -210,6 +210,7 @@ class Travis::Api::App end def fetch + retried ||= false user = ::User.find_by_github_id(data['id']) info = drop_token ? self.info : self.info(github_oauth_token: token) @@ -225,6 +226,11 @@ class Travis::Api::App end user + rescue ActiveRecord::RecordNotUnique + unless retried + retried = true + retry + end end end From dd5cf36eee28dcc23a46c94169e50de5a49da8b1 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Sat, 26 Oct 2013 08:39:31 -0500 Subject: [PATCH 114/185] Handle JSON parsing errors --- lib/travis/api/app/base.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index 35e44766..082be3ea 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -19,6 +19,11 @@ class Travis::Api::App "This feature has not yet been implemented. Sorry :(\n\nPull Requests welcome!" end + error JSON::ParserError do + status 400 + "Invalid JSON in request body" + end + # hotfix?? def route_missing @app ? forward : halt(404) From 824f9cd21dc2fdde25ae13180b3d5dd7c82c9e11 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Sun, 27 Oct 2013 01:06:26 -0500 Subject: [PATCH 115/185] Move /jobs/:id/cancel to /jobs --- lib/travis/api/app/endpoint/jobs.rb | 58 ++++++++++++++--------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 513fb888..9d6af422 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -30,6 +30,35 @@ class Travis::Api::App end end + post '/:id/cancel' do + Metriks.meter("api.request.cancel_job").mark + + service = self.service(:cancel_job, params.merge(source: 'api')) + if !service.authorized? + json = { error: { + message: "You don't have access to cancel job(#{params[:id]})" + } } + + Metriks.meter("api.request.cancel_job.unauthorized").mark + status 403 + respond_with json + elsif !service.can_cancel? + json = { error: { + message: "The job(#{params[:id]}) can't be canceled", + code: 'cant_cancel' + } } + + Metriks.meter("api.request.cancel_job.cant_cancel").mark + status 422 + respond_with json + else + service.run + + Metriks.meter("api.request.cancel_job.success").mark + status 204 + end + end + def archive_url(path) "https://s3.amazonaws.com/#{hostname('archive')}#{path}" end @@ -38,34 +67,5 @@ class Travis::Api::App "#{name}#{'-staging' if Travis.env == 'staging'}.#{Travis.config.host.split('.')[-2, 2].join('.')}" end end - - post '/:id/cancel' do - Metriks.meter("api.request.cancel_job").mark - - service = self.service(:cancel_job, params.merge(source: 'api')) - if !service.authorized? - json = { error: { - message: "You don't have access to cancel job(#{params[:id]})" - } } - - Metriks.meter("api.request.cancel_job.unauthorized").mark - status 403 - respond_with json - elsif !service.can_cancel? - json = { error: { - message: "The job(#{params[:id]}) can't be canceled", - code: 'cant_cancel' - } } - - Metriks.meter("api.request.cancel_job.cant_cancel").mark - status 422 - respond_with json - else - service.run - - Metriks.meter("api.request.cancel_job.success").mark - status 204 - end - end end end From 87674f52bbd66a2b645d514811db0821a97670fb Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 28 Oct 2013 17:37:50 +0100 Subject: [PATCH 116/185] Redirect to web client on insufficient oauth scopes --- lib/travis/api/app/endpoint/authorization.rb | 32 +++++++++-- .../authorization/user_manager_spec.rb | 4 +- spec/unit/endpoint/authorization_spec.rb | 56 +++++++++++++++++++ 3 files changed, 84 insertions(+), 8 deletions(-) diff --git a/lib/travis/api/app/endpoint/authorization.rb b/lib/travis/api/app/endpoint/authorization.rb index 80a05363..ce48fd49 100644 --- a/lib/travis/api/app/endpoint/authorization.rb +++ b/lib/travis/api/app/endpoint/authorization.rb @@ -202,6 +202,14 @@ class Travis::Api::App class UserManager < Struct.new(:data, :token, :drop_token) include User::Renaming + attr_accessor :user + + def initialize(*) + super + + @user = ::User.find_by_github_id(data['id']) + end + def info(attributes = {}) info = data.to_hash.slice('name', 'login', 'gravatar_id') info.merge! attributes.stringify_keys @@ -209,9 +217,12 @@ class Travis::Api::App info end + def user_exists? + user + end + def fetch retried ||= false - user = ::User.find_by_github_id(data['id']) info = drop_token ? self.info : self.info(github_oauth_token: token) ActiveRecord::Base.transaction do @@ -219,7 +230,7 @@ class Travis::Api::App rename_repos_owner(user.login, info['login']) user.update_attributes info else - user = ::User.create! info + self.user = ::User.create! info end nullify_logins(user.github_id, user.login) @@ -235,11 +246,20 @@ class Travis::Api::App end def user_for_github_token(token, drop_token = false) - data = GH.with(token: token.to_s, client_id: nil) { GH['user'] } - scopes = parse_scopes data.headers['x-oauth-scopes'] - halt 403, 'insufficient access: %p' unless acceptable? scopes + data = GH.with(token: token.to_s, client_id: nil) { GH['user'] } + scopes = parse_scopes data.headers['x-oauth-scopes'] + manager = UserManager.new(data, token, drop_token) - user = UserManager.new(data, token, drop_token).fetch + unless acceptable? scopes + # TODO: we should probably only redirect if this is a web + # oauth request, are there any other possibilities to + # consider? + url = Travis.config.oauth2.insufficient_access_redirect_url + url += "#existing-user" if manager.user_exists? + redirect to(url) + end + + user = manager.fetch halt 403, 'not a Travis user' if user.nil? user end diff --git a/spec/unit/endpoint/authorization/user_manager_spec.rb b/spec/unit/endpoint/authorization/user_manager_spec.rb index d55c68fb..914cca27 100644 --- a/spec/unit/endpoint/authorization/user_manager_spec.rb +++ b/spec/unit/endpoint/authorization/user_manager_spec.rb @@ -30,11 +30,11 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do } it 'drops the token when drop_token is set to true' do - manager = described_class.new(data, 'abc123', true) - user = stub('user', login: 'drogus', github_id: 456) User.expects(:find_by_github_id).with(456).returns(user) + manager = described_class.new(data, 'abc123', true) + attributes = { login: 'drogus', github_id: 456 }.stringify_keys user.expects(:update_attributes).with(attributes) diff --git a/spec/unit/endpoint/authorization_spec.rb b/spec/unit/endpoint/authorization_spec.rb index 12f8529c..e8425082 100644 --- a/spec/unit/endpoint/authorization_spec.rb +++ b/spec/unit/endpoint/authorization_spec.rb @@ -23,6 +23,62 @@ describe Travis::Api::App::Endpoint::Authorization do pending "not yet implemented" end + describe "GET /auth/handshake" do + describe 'with insufficient oauth permissions' do + before do + # TODO: this is a first try of writing tests for authorization, it does not look pretty + # but I wanted to have something to start with, later on I would like to extract + # this flow to a class, which would be easier to test. + @original_config = Travis.config.oauth2 + Travis.config.oauth2 = { + authorization_server: 'https://foobar.com', + access_token_path: '/access_token_path', + client_id: 'client-id', + client_secret: 'client-secret', + scope: 'public_repo,user:email,new_scope', + insufficient_access_redirect_url: 'https://travis-ci.org/insufficient_access' + } + Travis.redis.sadd('github:states', 'github-state') + + response = mock('response') + response.expects(:body).returns('access_token=foobarbaz-token') + Faraday.expects(:post).with('https://foobar.com/access_token_path', + client_id: 'client-id', + client_secret: 'client-secret', + scope: 'public_repo,user:email,new_scope', + redirect_uri: 'http://example.org/auth/handshake', + state: 'github-state', + code: 'oauth-code').returns(response) + + data = { 'id' => 111 } + data.expects(:headers).returns('x-oauth-scopes' => 'public_repo,user:email') + GH.expects(:with).with(token: 'foobarbaz-token', client_id: nil).returns(data) + end + + after do + Travis.config.oauth2 = @original_config + Travis.redis.srem('github:states', 'github-state') + # this is cached after first run, so if we change scopes, it will stay + # like that for the rest of the run + User::Oauth.instance_variable_set("@wanted_scopes", nil) + end + + it 'redirects to insufficient access page' do + response = get '/auth/handshake?state=github-state&code=oauth-code' + response.should redirect_to('https://travis-ci.org/insufficient_access') + end + + it 'redirects to insufficient access page for existing user' do + user = mock('user') + User.expects(:find_by_github_id).with(111).returns(user) + expect { + response = get '/auth/handshake?state=github-state&code=oauth-code' + response.should redirect_to('https://travis-ci.org/insufficient_access#existing-user') + }.to_not change { User.count } + end + end + end + describe 'POST /auth/github' do before do data = { 'id' => user.github_id, 'name' => user.name, 'login' => user.login, 'gravatar_id' => user.gravatar_id } From 018c3b3228886ea89a74ecf2175178cfd71d5fd1 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Mon, 4 Nov 2013 10:08:58 +0100 Subject: [PATCH 117/185] update gemspec --- travis-api.gemspec | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/travis-api.gemspec b/travis-api.gemspec index 810b381e..b6596011 100644 --- a/travis-api.gemspec +++ b/travis-api.gemspec @@ -9,9 +9,9 @@ Gem::Specification.new do |s| s.require_path = 'lib' s.authors = [ - "Sven Fuchs", - "Konstantin Haase", "Piotr Sarnacki", + "Konstantin Haase", + "Sven Fuchs", "Josh Kalderimis", "Mathias Meyer", "Henrik Hodne", @@ -20,24 +20,29 @@ Gem::Specification.new do |s| "Steve Richert", "Brian Ford", "Nick Schonning", - "James Dennes" + "Patrick Williams", + "James Dennes", + "Tim Carey-Smith" ] s.email = [ + "drogus@gmail.com", "konstantin.mailinglists@googlemail.com", "me@svenfuchs.com", - "drogus@gmail.com", "josh.kalderimis@gmail.com", "meyer@paperplanes.de", "me@henrikhodne.com", - "svenfuchs@artweb-design.de", + "henrik@hodne.io", + "konstantin.haase@gmail.com", "andre@arko.net", + "svenfuchs@artweb-design.de", "sferik@gmail.com", "steve.richert@gmail.com", "bford@engineyard.com", - "jdennes@gmail.com", "nschonni@gmail.com", - "konstantin.haase@gmail.com" + "jdennes@gmail.com", + "tim@spork.in", + "patrick@bittorrent.com" ] s.files = [ @@ -48,6 +53,8 @@ Gem::Specification.new do |s| "config.ru", "config/database.yml", "config/newrelic.yml", + "config/nginx.conf.erb", + "config/puma-config.rb", "config/unicorn.rb", "docs/00_overview.md", "docs/01_cross_origin.md", @@ -107,6 +114,7 @@ Gem::Specification.new do |s| "lib/travis/api/app/endpoint/repos.rb", "lib/travis/api/app/endpoint/requests.rb", "lib/travis/api/app/endpoint/stats.rb", + "lib/travis/api/app/endpoint/uptime.rb", "lib/travis/api/app/endpoint/users.rb", "lib/travis/api/app/endpoint/workers.rb", "lib/travis/api/app/extensions.rb", @@ -145,6 +153,7 @@ Gem::Specification.new do |s| "spec/integration/responders_spec.rb", "spec/integration/routes.backup.rb", "spec/integration/scopes_spec.rb", + "spec/integration/uptime_spec.rb", "spec/integration/v1/branches_spec.rb", "spec/integration/v1/builds_spec.rb", "spec/integration/v1/hooks_spec.rb", From 44e1db3944f3db71af293159fb83f6024a70f9c5 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Mon, 4 Nov 2013 10:23:17 +0100 Subject: [PATCH 118/185] add API endpoints for listing and deleting caches --- Gemfile.lock | 6 +++++- lib/travis/api/app/endpoint/repos.rb | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 86931215..2d004666 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: bcc14ad2fafff932f1b681a332b6435b50ddb099 + revision: 9db978cabd740dddbc94d105cc4242b56afe2e9f specs: travis-core (0.0.1) actionmailer (~> 3.2.12) @@ -39,6 +39,7 @@ GIT rake redis (~> 3.0) rollout (~> 1.1.0) + s3 (~> 0.3) simple_states (~> 1.0.0) thor (~> 0.14.6) @@ -177,6 +178,7 @@ GEM newrelic_rpm (3.6.7.152) pg (0.13.2) polyglot (0.3.3) + proxies (0.2.1) pry (0.9.12.2) coderay (~> 1.0.5) method_source (~> 0.8) @@ -226,6 +228,8 @@ GEM rspec-expectations (2.14.0) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.14.1) + s3 (0.3.17) + proxies (~> 0.2.0) sidekiq (2.5.4) celluloid (~> 0.12.0) connection_pool (~> 0.9.2) diff --git a/lib/travis/api/app/endpoint/repos.rb b/lib/travis/api/app/endpoint/repos.rb index d6cf9f16..fd4a36a5 100644 --- a/lib/travis/api/app/endpoint/repos.rb +++ b/lib/travis/api/app/endpoint/repos.rb @@ -68,6 +68,16 @@ class Travis::Api::App respond_with service(:find_branch, params), type: :branch, version: :v2 end + # List caches for a given repo. Can be filtered with `branch` and `match` query parameter. + get '/:repository_id/caches', scope: :private do + respond_with service(:find_caches, params), type: :caches, version: :v2 + end + + # Delete caches for a given repo. Can be filtered with `branch` and `match` query parameter. + delete '/:repository_id/caches', scope: :private do + respond_with service(:delete_caches, params), type: :caches, version: :v2 + end + # Gets the repository with the given name. # # ### Response @@ -129,6 +139,16 @@ class Travis::Api::App get '/:owner_name/:name/branches/:branch' do respond_with service(:find_branch, params), type: :branch, version: :v2 end + + # List caches for a given repo. Can be filtered with `branch` and `match` query parameter. + get '/:owner_name/:name/caches', scope: :private do + respond_with service(:find_caches, params), type: :caches, version: :v2 + end + + # Delete caches for a given repo. Can be filtered with `branch` and `match` query parameter. + delete '/:owner_name/:name/caches', scope: :private do + respond_with service(:delete_caches, params), type: :caches, version: :v2 + end end end end From 342df12b14516944407047463872dc3e8f37e1ea Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Mon, 4 Nov 2013 19:24:17 +0100 Subject: [PATCH 119/185] remove old workers endpoints --- lib/travis/api/app/endpoint/workers.rb | 15 --------------- spec/integration/v1/workers_spec.rb | 12 ------------ spec/integration/v2/workers_spec.rb | 12 ------------ spec/unit/endpoint/workers_spec.rb | 5 ----- 4 files changed, 44 deletions(-) delete mode 100644 lib/travis/api/app/endpoint/workers.rb delete mode 100644 spec/integration/v1/workers_spec.rb delete mode 100644 spec/integration/v2/workers_spec.rb delete mode 100644 spec/unit/endpoint/workers_spec.rb diff --git a/lib/travis/api/app/endpoint/workers.rb b/lib/travis/api/app/endpoint/workers.rb deleted file mode 100644 index bd648785..00000000 --- a/lib/travis/api/app/endpoint/workers.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'travis/api/app' - -class Travis::Api::App - class Endpoint - class Workers < Endpoint - get '/' do - respond_with service(:find_workers, params), type: :workers - end - - get '/:id' do - respond_with service(:find_worker, params), type: :worker - end - end - end -end diff --git a/spec/integration/v1/workers_spec.rb b/spec/integration/v1/workers_spec.rb deleted file mode 100644 index 1c897384..00000000 --- a/spec/integration/v1/workers_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'spec_helper' - -describe 'Workers' do - let!(:workers) { [Worker.create(full_name: 'one'), Worker.create(full_name: 'two')] } - let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } - - it 'GET /workers' do - response = get '/workers', {}, headers - response.should deliver_json_for(Worker.all, version: 'v1', type: 'workers') - end -end - diff --git a/spec/integration/v2/workers_spec.rb b/spec/integration/v2/workers_spec.rb deleted file mode 100644 index 120934a4..00000000 --- a/spec/integration/v2/workers_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'spec_helper' - -describe 'Workers' do - let!(:workers) { [Worker.create(full_name: 'one'), Worker.create(full_name: 'two')] } - let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } - - it 'GET /workers' do - response = get '/workers', {}, headers - response.should deliver_json_for(Worker.all, version: 'v2', type: 'workers') - end -end - diff --git a/spec/unit/endpoint/workers_spec.rb b/spec/unit/endpoint/workers_spec.rb deleted file mode 100644 index f169b161..00000000 --- a/spec/unit/endpoint/workers_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe Travis::Api::App::Endpoint::Workers do - it 'has to be tested' -end From 54060dbfc6f87a9297c6dbb81e94358a056c787e Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Tue, 5 Nov 2013 00:18:14 +0100 Subject: [PATCH 120/185] removed the events endpoint it isn't used, and there are no tests, i think it's safe to remove --- lib/travis/api/app/endpoint/events.rb | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 lib/travis/api/app/endpoint/events.rb diff --git a/lib/travis/api/app/endpoint/events.rb b/lib/travis/api/app/endpoint/events.rb deleted file mode 100644 index 47d43fc5..00000000 --- a/lib/travis/api/app/endpoint/events.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'travis/api/app' - -class Travis::Api::App - class Endpoint - class Events < Endpoint - get '/' do - respond_with service(:find_events, params), type: :events - end - end - end -end - From 26edaf644fb46a68e5291bb62245c06a55ea9a0d Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Tue, 5 Nov 2013 01:05:21 +0100 Subject: [PATCH 121/185] remove deprecated artifacts endpoint --- lib/travis/api/app/endpoint/artifacts.rb | 16 --------- spec/unit/endpoint/artifacts_spec.rb | 44 ------------------------ 2 files changed, 60 deletions(-) delete mode 100644 lib/travis/api/app/endpoint/artifacts.rb delete mode 100644 spec/unit/endpoint/artifacts_spec.rb diff --git a/lib/travis/api/app/endpoint/artifacts.rb b/lib/travis/api/app/endpoint/artifacts.rb deleted file mode 100644 index cd35a570..00000000 --- a/lib/travis/api/app/endpoint/artifacts.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'travis/api/app' - -class Travis::Api::App - class Endpoint - # Artifacts are generated by builds. Currently we only expose logs as - # artifacts - # - # **DEPRECATED** will be removed as soon as the client uses /logs/:id - class Artifacts < Endpoint - # Fetches an artifact by it's *id*. - get '/:id' do |id| - respond_with service(:find_log, params) - end - end - end -end diff --git a/spec/unit/endpoint/artifacts_spec.rb b/spec/unit/endpoint/artifacts_spec.rb deleted file mode 100644 index b701cff7..00000000 --- a/spec/unit/endpoint/artifacts_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'spec_helper' - -describe Travis::Api::App::Endpoint::Artifacts do - let(:artifact) { Factory(:log) } - let(:id) { artifact.id } - - describe 'GET /artifacts/:id' do - it 'loads the artifact' do - get("/artifacts/#{id}", {}, 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json, */*; q=0.01').should be_ok - end - end - - describe 'GET /artifacts/:id.txt' do - it 'loads the artifact' do - response = get("/artifacts/#{id}.txt", {}) - - response.should be_ok - response.body.should == artifact.content - response.headers['Content-Disposition'].should == "inline; filename=\"#{artifact.id}\"" - end - - it 'sets Content-Disposition to attachment with attachment=true param' do - response = get("/artifacts/#{id}.txt", {'attachment' => true}) - - response.should be_ok - response.body.should == artifact.content - response.headers['Content-Disposition'].should == "attachment; filename=\"#{artifact.id}\"" - end - - describe 'with deansi param' do - let(:content) { - "Fetching (0%)\rFetching (10%)\rFetching (100%)\n\e[32m" - } - let(:artifact) { Factory(:log, :content => content) } - - it 'clears ansi escape control characters' do - response = get("/artifacts/#{id}.txt", {'deansi' => true}) - - response.should be_ok - response.body.should == "Fetching (100%)\n" - end - end - end -end From 5f3e53da280d1b2b4fdfa5f155aeeb665216c61a Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Mon, 4 Nov 2013 21:06:38 -0600 Subject: [PATCH 122/185] Update API docs to use new styles --- lib/travis/api/app/endpoint/documentation.rb | 61 +- .../css/bootstrap-responsive.css | 808 -- .../css/bootstrap-responsive.min.css | 9 - .../endpoint/documentation/css/bootstrap.css | 4960 --------- .../documentation/css/bootstrap.min.css | 9 - .../endpoint/documentation/css/prettify.css | 31 - .../app/endpoint/documentation/css/style.css | 830 +- .../img/glyphicons-halflings-white.png | Bin 8777 -> 0 bytes .../img/glyphicons-halflings.png | Bin 13826 -> 0 bytes .../documentation/img/grid-18px-masked.png | Bin 405 -> 0 bytes .../endpoint/documentation/js/bootstrap.js | 1824 ---- .../documentation/js/bootstrap.min.js | 6 - .../app/endpoint/documentation/js/jquery.js | 9252 ----------------- .../endpoint/documentation/js/lang-apollo.js | 2 - .../app/endpoint/documentation/js/lang-clj.js | 18 - .../app/endpoint/documentation/js/lang-css.js | 2 - .../app/endpoint/documentation/js/lang-go.js | 1 - .../app/endpoint/documentation/js/lang-hs.js | 2 - .../endpoint/documentation/js/lang-lisp.js | 3 - .../app/endpoint/documentation/js/lang-lua.js | 2 - .../app/endpoint/documentation/js/lang-ml.js | 2 - .../app/endpoint/documentation/js/lang-n.js | 4 - .../endpoint/documentation/js/lang-proto.js | 1 - .../endpoint/documentation/js/lang-scala.js | 2 - .../app/endpoint/documentation/js/lang-sql.js | 2 - .../app/endpoint/documentation/js/lang-tex.js | 1 - .../app/endpoint/documentation/js/lang-vb.js | 2 - .../endpoint/documentation/js/lang-vhdl.js | 3 - .../endpoint/documentation/js/lang-wiki.js | 2 - .../app/endpoint/documentation/js/lang-xq.js | 3 - .../endpoint/documentation/js/lang-yaml.js | 2 - .../app/endpoint/documentation/js/prettify.js | 28 - 32 files changed, 574 insertions(+), 17298 deletions(-) delete mode 100644 lib/travis/api/app/endpoint/documentation/css/bootstrap-responsive.css delete mode 100644 lib/travis/api/app/endpoint/documentation/css/bootstrap-responsive.min.css delete mode 100644 lib/travis/api/app/endpoint/documentation/css/bootstrap.css delete mode 100644 lib/travis/api/app/endpoint/documentation/css/bootstrap.min.css delete mode 100644 lib/travis/api/app/endpoint/documentation/css/prettify.css delete mode 100644 lib/travis/api/app/endpoint/documentation/img/glyphicons-halflings-white.png delete mode 100644 lib/travis/api/app/endpoint/documentation/img/glyphicons-halflings.png delete mode 100644 lib/travis/api/app/endpoint/documentation/img/grid-18px-masked.png delete mode 100644 lib/travis/api/app/endpoint/documentation/js/bootstrap.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/bootstrap.min.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/jquery.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-apollo.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-clj.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-css.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-go.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-hs.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-lisp.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-lua.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-ml.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-n.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-proto.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-scala.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-sql.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-tex.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-vb.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-vhdl.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-wiki.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-xq.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/lang-yaml.js delete mode 100644 lib/travis/api/app/endpoint/documentation/js/prettify.js diff --git a/lib/travis/api/app/endpoint/documentation.rb b/lib/travis/api/app/endpoint/documentation.rb index 7d054b1c..781708a2 100644 --- a/lib/travis/api/app/endpoint/documentation.rb +++ b/lib/travis/api/app/endpoint/documentation.rb @@ -85,38 +85,28 @@ __END__ Travis API documentation - - - - - - - - + + + - + - -
+

The Travis API

+ <% general_docs.each do |doc| %> <%= erb :entry, locals: doc %> <% end %> @@ -163,22 +153,33 @@ __END__
-