diff --git a/.travis.yml b/.travis.yml index 67e6504c..27dc76a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby rvm: - 1.9.3 - rbx-19mode + - jruby-19mode before_script: - 'RAILS_ENV=test rake db:create db:schema:load --trace' notifications: @@ -9,3 +10,4 @@ notifications: matrix: allow_failures: - rvm: rbx-19mode + - rvm: jruby-19mode diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..0545a308 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,15 @@ +# Contributing to Travis-CI +Issues for any Travis-CI repo should be submitted to https://github.com/travis-ci/travis-ci/issues + +## Security Issues +***Any security issues should be submitted directly to [security@travis-ci.org](mailto:security@travis-ci.org)*** + +## Reporting Issues +- Explain what you expected to happen vs the actual results +- Include a screenshot if it helps illustrate the issue. https://github.com/blog/1347-issue-attachments +- What steps are required to reproduce the issue +- An example build that shows the issue + +## Submitting a PR to Travis-API + +See testing and setup notes in the base [README](https://github.com/travis-ci/travis-api) diff --git a/Gemfile b/Gemfile index c0555e45..ace4c1c0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,18 +1,18 @@ ruby '1.9.3' rescue nil -source :rubygems +source 'https://rubygems.org' gemspec -gem 'travis-support', github: 'travis-ci/travis-support' 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', github: 'sinatra/sinatra' -gem 'sinatra-contrib', github: 'sinatra/sinatra-contrib', require: nil +gem 'sinatra' #github: 'sinatra/sinatra' +gem 'sinatra-contrib', require: nil #github: 'sinatra/sinatra-contrib', require: nil # TODO need to release the gem as soon i'm certain this change makes sense gem 'simple_states', github: 'svenfuchs/simple_states', branch: 'sf-set-state-early' -gem 'unicorn' +gem 'puma', '1.6.3' gem "sentry-raven", github: 'getsentry/raven-ruby' gem 'yard-sinatra', github: 'rkh/yard-sinatra' gem 'rack-contrib', github: 'rack/rack-contrib' @@ -21,7 +21,9 @@ gem 'gh', github: 'rkh/gh' gem 'bunny' gem 'dalli' gem 'pry' -gem 'metriks', '0.9.9.2' +gem 'metriks', '0.9.9.2' + +gem 'ar-octopus', github: 'travis-ci/octopus', require: nil group :test do gem 'rspec', '~> 2.11' @@ -34,9 +36,10 @@ group :development do gem 'foreman' gem 'rerun' # gem 'debugger' + gem 'rb-fsevent', '~> 0.9.1' end group :development, :test do gem 'rake', '~> 0.9.2' - gem 'micro_migrations', git: 'http://gist.github.com/4269321.git' + gem 'micro_migrations', git: 'https://gist.github.com/4269321.git' end diff --git a/Gemfile.lock b/Gemfile.lock index e0bba5fe..1bfbf9ad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,10 @@ GIT remote: git://github.com/getsentry/raven-ruby.git - revision: a0f59d3974034b38891fb1d4a70ff45fa996e7c9 + revision: 267b33417a3ed43f552911cf353561a641ba9fb2 specs: - sentry-raven (0.4.0) + sentry-raven (0.4.6) faraday (>= 0.7.6) - hashie + hashie (>= 1.1.0) multi_json (~> 1.0) uuidtools @@ -17,11 +17,11 @@ GIT GIT remote: git://github.com/rkh/gh.git - revision: 1dece05c588c63e714520aae686589de1b3bcbd5 + revision: ff93c759591a66c9d5250cada5234d2adde95dd3 specs: - gh (0.9.1) + gh (0.11.1) addressable - backports (~> 2.3) + backports faraday (~> 0.8) multi_json (~> 1.0) net-http-persistent (>= 2.7) @@ -29,32 +29,11 @@ GIT GIT remote: git://github.com/rkh/yard-sinatra.git - revision: 3b1064eef407d2d288a5b96d258178a1e67b3b80 + revision: e61831bca0431b35eaa62fdd18acbc65f81322af specs: yard-sinatra (1.0.0) yard (~> 0.7) -GIT - remote: git://github.com/sinatra/sinatra-contrib.git - revision: 86c85007860bbaf596092547e7902ff5e0a07698 - specs: - sinatra-contrib (1.4.0) - backports (>= 2.0) - eventmachine - rack-protection - rack-test - sinatra (~> 1.4.0) - tilt (~> 1.3) - -GIT - remote: git://github.com/sinatra/sinatra.git - revision: 459369eb66224836f72e21bbece58c007f3422fa - specs: - sinatra (1.4.0) - rack (~> 1.4) - rack-protection (~> 1.3) - tilt (~> 1.3, >= 1.3.3) - GIT remote: git://github.com/svenfuchs/simple_states.git revision: b1d45144e6a758220d7b21f83b08dc92de0d3196 @@ -64,23 +43,30 @@ GIT activesupport hashr (~> 0.0.10) +GIT + remote: git://github.com/travis-ci/octopus.git + revision: 2d4cca475479516f47c3144971205f50c335ad35 + specs: + ar-octopus (0.5.0beta) + activerecord (>= 2.3.0) + activesupport (>= 2.3.0) + GIT remote: git://github.com/travis-ci/travis-core.git - revision: 259e48ffc68a67eff32848334025ef17ab58a3b3 + revision: 9ecc95058bd63f9f70799c7f9f8ad41cbd39b16c specs: travis-core (0.0.1) - actionmailer (~> 3.2.11) - activerecord (~> 3.2.11) + actionmailer (~> 3.2.12) + activerecord (~> 3.2.12) coder (~> 0.3.0) data_migrations (~> 0.0.1) gh hashr (~> 0.0.19) metriks (~> 0.9.7) multi_json - postmark-rails (~> 0.4.1) pusher (~> 0.11.0) - railties (~> 3.2.11) - rake (~> 0.9.2.2) + railties (~> 3.2.12) + rake redis (~> 3.0) rollout (~> 1.1.0) simple_states (~> 0.1.1) @@ -96,12 +82,12 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: cf916e10949db43ce6f2b6f86082b367f04acfcd + revision: 5463f10e58563e79b950da8c6c392d1e80ec3013 specs: travis-support (0.0.1) GIT - remote: http://gist.github.com/4269321.git + remote: https://gist.github.com/4269321.git revision: 8e2d21b924a69dd48191df6a18e51769f5a88614 specs: micro_migrations (0.0.1) @@ -112,10 +98,10 @@ PATH travis-api (0.0.1) backports (~> 2.5) hubble (~> 0.1) - newrelic_rpm (~> 3.5.0) + newrelic_rpm (~> 3.6.1.88) pg (~> 0.13.2) rack-contrib (~> 1.1) - rack-ssl (~> 1.3) + rack-ssl (~> 1.3, >= 1.3.3) redcarpet (~> 2.1) sinatra (~> 1.3) sinatra-contrib (~> 1.3) @@ -124,73 +110,78 @@ PATH travis-support GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: - actionmailer (3.2.11) - actionpack (= 3.2.11) - mail (~> 2.4.4) - actionpack (3.2.11) - activemodel (= 3.2.11) - activesupport (= 3.2.11) + actionmailer (3.2.13) + actionpack (= 3.2.13) + mail (~> 2.5.3) + actionpack (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) - rack (~> 1.4.0) + rack (~> 1.4.5) rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) - activemodel (3.2.11) - activesupport (= 3.2.11) + activemodel (3.2.13) + activesupport (= 3.2.13) builder (~> 3.0.0) - activerecord (3.2.11) - activemodel (= 3.2.11) - activesupport (= 3.2.11) + activerecord (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activesupport (3.2.11) - i18n (~> 0.6) + activesupport (3.2.13) + i18n (= 0.6.1) multi_json (~> 1.0) - addressable (2.3.2) + addressable (2.3.4) arel (3.0.2) - atomic (1.0.1) + atomic (1.1.9) avl_tree (1.1.3) - backports (2.7.1) + backports (2.8.2) builder (3.0.4) bunny (0.8.0) celluloid (0.12.4) facter (>= 1.6.12) timers (>= 1.0.0) coder (0.3.0) - coderay (1.0.8) + coderay (1.0.9) connection_pool (0.9.3) daemons (1.1.9) - dalli (2.6.0) + dalli (2.6.3) data_migrations (0.0.1) activerecord rake database_cleaner (0.8.0) - diff-lcs (1.1.3) + diff-lcs (1.2.4) + dotenv (0.7.0) erubis (2.7.0) - eventmachine (1.0.0) - facter (1.6.17) + eventmachine (1.0.3) + facter (1.7.0) factory_girl (2.4.2) activesupport - faraday (0.8.4) + faraday (0.8.7) multipart-post (~> 1.1) - foreman (0.61.0) + ffi (1.8.1) + foreman (0.63.0) + dotenv (>= 0.7) thor (>= 0.13.6) - hashie (1.2.0) + hashie (2.0.4) hashr (0.0.22) - hike (1.2.1) - hitimes (1.1.1) + hike (1.2.2) + hitimes (1.2.1) hubble (0.1.2) yajl-ruby (~> 1.1) i18n (0.6.1) journey (1.0.4) - json (1.7.6) - kgio (2.8.0) - listen (0.7.2) - mail (2.4.4) + json (1.7.7) + listen (1.0.3) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) + rb-kqueue (>= 0.2) + mail (2.5.3) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -200,101 +191,108 @@ GEM atomic (~> 1.0) avl_tree (~> 1.1.2) hitimes (~> 1.1) - mime-types (1.19) - mocha (0.13.1) + mime-types (1.23) + mocha (0.13.3) metaclass (~> 0.0.1) - multi_json (1.5.0) - multipart-post (1.1.5) + multi_json (1.7.3) + multipart-post (1.2.0) net-http-persistent (2.8) net-http-pipeline (1.0.1) - newrelic_rpm (3.5.5.38) + newrelic_rpm (3.6.1.88) pg (0.13.2) polyglot (0.3.3) - postmark (0.9.18) - json - rake - postmark-rails (0.4.1) - actionmailer - postmark (>= 0.9.0) - rake - pry (0.9.11.4) + pry (0.9.12.1) coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.4) - pusher (0.11.2) + puma (1.6.3) + rack (~> 1.2) + pusher (0.11.3) multi_json (~> 1.0) signature (~> 0.1.6) - rack (1.4.4) + rack (1.4.5) rack-cache (1.2) rack (>= 0.4) - rack-protection (1.3.2) + rack-protection (1.5.0) rack - rack-ssl (1.3.2) + rack-ssl (1.3.3) rack rack-test (0.6.2) rack (>= 1.0) - railties (3.2.11) - actionpack (= 3.2.11) - activesupport (= 3.2.11) + railties (3.2.13) + actionpack (= 3.2.13) + activesupport (= 3.2.13) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - raindrops (0.10.0) - rake (0.9.2.2) - rdoc (3.12) + rake (0.9.6) + rb-fsevent (0.9.3) + rb-inotify (0.9.0) + ffi (>= 0.5.0) + rb-kqueue (0.2.0) + ffi (>= 0.5.0) + rdoc (3.12.2) json (~> 1.4) redcarpet (2.2.2) - redis (3.0.2) - redis-namespace (1.2.1) + redis (3.0.4) + redis-namespace (1.3.0) redis (~> 3.0.0) - rerun (0.7.1) - listen + rerun (0.8.1) + listen (>= 1.0.3) rollout (1.1.0) - rspec (2.12.0) - rspec-core (~> 2.12.0) - rspec-expectations (~> 2.12.0) - rspec-mocks (~> 2.12.0) - rspec-core (2.12.2) - rspec-expectations (2.12.1) - diff-lcs (~> 1.1.3) - rspec-mocks (2.12.1) + 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) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.13.1) sidekiq (2.5.4) celluloid (~> 0.12.0) connection_pool (~> 0.9.2) multi_json (~> 1) redis (~> 3) redis-namespace - signature (0.1.6) - slop (3.4.3) + signature (0.1.7) + sinatra (1.3.6) + rack (~> 1.4) + rack-protection (~> 1.3) + tilt (~> 1.3, >= 1.3.3) + sinatra-contrib (1.3.2) + backports (>= 2.0) + eventmachine + rack-protection + rack-test + sinatra (~> 1.3.0) + tilt (~> 1.3) + slop (3.4.4) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - thin (1.5.0) + thin (1.5.1) daemons (>= 1.0.9) eventmachine (>= 0.12.6) rack (>= 1.0.0) thor (0.14.6) - tilt (1.3.3) + tilt (1.4.1) timers (1.1.0) treetop (1.4.12) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.35) - unicorn (4.5.0) - kgio (~> 2.6) - rack - raindrops (~> 0.7) - uuidtools (2.1.3) + tzinfo (0.3.37) + uuidtools (2.1.4) yajl-ruby (1.1.0) - yard (0.8.3) + yard (0.8.6.1) PLATFORMS ruby DEPENDENCIES + ar-octopus! bunny dalli database_cleaner (~> 0.8.0) @@ -305,18 +303,19 @@ DEPENDENCIES micro_migrations! mocha (~> 0.12) pry + puma (= 1.6.3) rack-cache (~> 1.2) rack-contrib! rake (~> 0.9.2) + rb-fsevent (~> 0.9.1) rerun rspec (~> 2.11) sentry-raven! simple_states! - sinatra! - sinatra-contrib! + sinatra + sinatra-contrib travis-api! travis-core! travis-sidekiqs! travis-support! - unicorn yard-sinatra! diff --git a/Rakefile b/Rakefile index 5c5bce13..29502405 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,11 @@ require 'bundler/setup' ENV['SCHEMA'] = "#{Gem.loaded_specs['travis-core'].full_gem_path}/db/schema.rb" -require 'micro_migrations' +begin + require 'micro_migrations' +rescue LoadError + # we can't load micro migrations on production +end require 'travis' begin @@ -33,3 +37,6 @@ task 'travis-api.gemspec' do end task default: 'travis-api.gemspec' + +tasks_path = File.expand_path('../lib/tasks/*.rake', __FILE__) +Dir.glob(tasks_path).each { |r| import r } diff --git a/config.ru b/config.ru index 7806e127..8fb5947a 100644 --- a/config.ru +++ b/config.ru @@ -7,10 +7,12 @@ $stdout.sync = true require 'travis/api/app' require 'core_ext/module/load_constants' -# models = Travis::Model.constants.map(&:to_s) -# only = [/^(ActiveRecord|ActiveModel|Travis|GH|#{models.join('|')})/] -# [Travis::Api, Travis, GH].each do |target| -# target.load_constants! :only => only, :skip => ['Travis::Memory', 'GH::ResponseWrapper'], :debug => false -# end +models = Travis::Model.constants.map(&:to_s) +only = [/^(ActiveRecord|ActiveModel|Travis|GH|#{models.join('|')})/] +skip = ['Travis::Memory', 'GH::ResponseWrapper', 'Travis::NewRelic'] + +[Travis::Api, Travis, GH].each do |target| + target.load_constants! :only => only, :skip => skip, :debug => false +end run Travis::Api::App.new diff --git a/lib/tasks/build_update_branch.rake b/lib/tasks/build_update_branch.rake new file mode 100644 index 00000000..55a4575b --- /dev/null +++ b/lib/tasks/build_update_branch.rake @@ -0,0 +1,23 @@ +namespace :build do + namespace :migrate do + task :branch do + require 'travis' + Travis::Database.connect + + + Build.select(['id', 'commit_id']).pushes.includes(:commit).find_in_batches do |builds| + branches = Hash.new { |h, k| h[k] = [] } + + builds.each do |build| + #next if build.branch + branches[build.commit.branch] << build.id + end + + branches.each do |branch, ids| + Build.where(id: ids).update_all(branch: branch) + end + end; nil + + end + end +end diff --git a/lib/tasks/build_update_pull_request_data.rake b/lib/tasks/build_update_pull_request_data.rake new file mode 100644 index 00000000..0fbcd681 --- /dev/null +++ b/lib/tasks/build_update_pull_request_data.rake @@ -0,0 +1,22 @@ +namespace :build do + namespace :migrate do + task :pull_request_data do + require 'travis' + Travis::Database.connect + + Build.pull_requests.includes(:request).order('id DESC').find_in_batches do |builds| + Build.transaction do + builds.each do |build| + next if build.pull_request_number && build.pull_request_title + attrs = { + :pull_request_number => build.request.pull_request_number, + :pull_request_title => build.request.pull_request_title + } + + Build.where(id: build.id).update_all(attrs) + end + end + end + end + end +end diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index bedd863f..68ed7981 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -52,7 +52,11 @@ module Travis::Api end def self.deploy_sha - @deploy_sha ||= File.exist?('.deploy_sha') ? File.read('.deploy-sha')[0..7] : 'deploy-sha' + @deploy_sha ||= File.exist?(deploy_sha_path) ? File.read(deploy_sha_path)[0..7] : 'deploy-sha' + end + + def self.deploy_sha_path + File.expand_path('../../../../.deploy-sha', __FILE__) end attr_accessor :app @@ -70,8 +74,8 @@ module Travis::Api if Travis::Features.feature_active?(:use_rack_cache) && memcache_server use Rack::Cache, verbose: true, - metastore: "memcached://#{memcache_servers}/#{self.class.deploy_sha}", - entitystore: "memcached://#{memcache_servers}/#{self.class.deploy_sha}" + metastore: "memcached://#{memcache_servers}/#{Travis::Api::App.deploy_sha}", + entitystore: "memcached://#{memcache_servers}/#{Travis::Api::App.deploy_sha}" end use Rack::Deflater @@ -100,6 +104,10 @@ module Travis::Api private + def self.console? + defined? Travis::Console + end + def self.setup! setup_travis load_endpoints @@ -109,18 +117,50 @@ module Travis::Api def self.setup_travis Travis::Amqp.config = Travis.config.amqp - Travis::Database.connect + + setup_database_connections + Travis::Features.start - Sidekiq.configure_client do |config| - config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace) + + 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) + end end - Raven.configure do |config| - config.dsn = Travis.config.sentry.dsn - end if Travis.config.sentry + if Travis.env == 'production' and not console? + Raven.configure do |config| + config.dsn = Travis.config.sentry.dsn + end if Travis.config.sentry - Travis::LogSubscriber::ActiveRecordMetrics.attach - $metriks_reporter = Metriks::Reporter::Logger.new + Travis::LogSubscriber::ActiveRecordMetrics.attach + Travis::Notification.setup + end + end + + 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 + end end def self.load_endpoints diff --git a/lib/travis/api/app/access_token.rb b/lib/travis/api/app/access_token.rb index a8e324b9..99a70ad5 100644 --- a/lib/travis/api/app/access_token.rb +++ b/lib/travis/api/app/access_token.rb @@ -4,7 +4,7 @@ require 'securerandom' class Travis::Api::App class AccessToken DEFAULT_SCOPES = [:public, :private] - attr_reader :token, :scopes, :user_id, :app_id + attr_reader :token, :scopes, :user_id, :app_id, :expires_in, :extra def self.create(options = {}) new(options).tap(&:save) @@ -18,25 +18,40 @@ class Travis::Api::App def self.find_by_token(token) return token if token.is_a? self user_id, app_id, *scopes = redis.lrange(key(token), 0, -1) - new(token: token, scopes: scopes, user_id: user_id, app_id: app_id) if user_id + extra = decode_json(scopes.pop) if scopes.last && scopes.last =~ /^json:/ + new(token: token, scopes: scopes, user_id: user_id, app_id: app_id, extra: extra) if user_id end def initialize(options = {}) raise ArgumentError, 'must supply either user_id or user' unless options.key?(:user) ^ options.key?(:user_id) raise ArgumentError, 'must supply app_id' unless options.key?(:app_id) + begin + @expires_in = Integer(options[:expires_in]) if options[:expires_in] + rescue ArgumentError + raise ArgumentError, 'expires_in must be of integer type' + end + @app_id = Integer(options[:app_id]) @scopes = Array(options[:scopes] || options[:scope] || DEFAULT_SCOPES).map(&:to_sym) @user = options[:user] @user_id = Integer(options[:user_id] || @user.id) @token = options[:token] || reuse_token || SecureRandom.urlsafe_base64(16) + @extra = options[:extra] end def save key = key(token) redis.del(key) - redis.rpush(key, [user_id, app_id, *scopes].map(&:to_s)) + data = [user_id, app_id, *scopes] + data << encode_json(extra) if extra + redis.rpush(key, data.map(&:to_s)) redis.set(reuse_key, token) + + if expires_in + redis.expire(reuse_key, expires_in) + redis.expire(key, expires_in) + end end def user @@ -60,6 +75,14 @@ class Travis::Api::App def key(token) "t:#{token}" end + + def encode_json(hash) + 'json:' + Base64.encode64(hash.to_json) + end + + def decode_json(json) + JSON.parse(Base64.decode64(json.gsub(/^json:/, ''))) + end end include Helpers @@ -68,7 +91,7 @@ class Travis::Api::App private def reuse_token - redis.get(reuse_key) + redis.get(reuse_key) unless expires_in end def reuse_key diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index 4f61f6a6..4fbf40c8 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -1,6 +1,5 @@ require 'travis/api/app' require 'sinatra/base' -require 'new_relic/agent/instrumentation/rack' class Travis::Api::App # Superclass for any endpoint and middleware. @@ -18,6 +17,17 @@ class Travis::Api::App "This feature has not yet been implemented. Sorry :(\n\nPull Requests welcome!" end + # hotfix?? + def route_missing + @app ? forward : halt(404) + end + + def call(env) + super + rescue Sinatra::NotFound + [404, {'Content-Type' => 'text/plain'}, ['Tell Konstantin to fix this!']] + end + configure do # We pull in certain protection middleware in App. # Being token based makes us invulnerable to common diff --git a/lib/travis/api/app/endpoint.rb b/lib/travis/api/app/endpoint.rb index 2716ff13..11c82afc 100644 --- a/lib/travis/api/app/endpoint.rb +++ b/lib/travis/api/app/endpoint.rb @@ -10,7 +10,7 @@ class Travis::Api::App set(:prefix) { "/" << name[/[^:]+$/].underscore } set disable_root_endpoint: false register :scoping - helpers :current_user, :flash + helpers :current_user, :flash, :db_follower # TODO hmmm? before { flash.clear } diff --git a/lib/travis/api/app/endpoint/artifacts.rb b/lib/travis/api/app/endpoint/artifacts.rb index 43fb9040..cd35a570 100644 --- a/lib/travis/api/app/endpoint/artifacts.rb +++ b/lib/travis/api/app/endpoint/artifacts.rb @@ -4,10 +4,12 @@ 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_artifact, params) + respond_with service(:find_log, params) end end end diff --git a/lib/travis/api/app/endpoint/authorization.rb b/lib/travis/api/app/endpoint/authorization.rb index eb5a1e57..f433cfc1 100644 --- a/lib/travis/api/app/endpoint/authorization.rb +++ b/lib/travis/api/app/endpoint/authorization.rb @@ -218,7 +218,7 @@ class Travis::Api::App end def user_for_github_token(token, drop_token = false) - data = GH.with(token: token.to_s) { GH['user'] } + 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 diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index fe7b21c4..3ef22141 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -4,7 +4,8 @@ class Travis::Api::App class Endpoint class Builds < Endpoint get '/' do - respond_with service(:find_builds, params) + name = params[:branches] ? :find_branches : :find_builds + respond_with service(name, params) end get '/:id' do diff --git a/lib/travis/api/app/endpoint/documentation.rb b/lib/travis/api/app/endpoint/documentation.rb index f7feaaf6..7d054b1c 100644 --- a/lib/travis/api/app/endpoint/documentation.rb +++ b/lib/travis/api/app/endpoint/documentation.rb @@ -1,4 +1,5 @@ require 'travis/api/app' +require 'travis/api/app/endpoint/documentation/resources' class Travis::Api::App class Endpoint @@ -44,6 +45,7 @@ class Travis::Api::App def with_code_highlighting(str) str. + gsub(/json\(:([^)]+)\)/) { "
" + Resources::Helpers.json($1) + "" }. gsub('
/, ''). gsub(/TODO:?/, 'TODO') @@ -81,154 +83,116 @@ __END__ - +Travis API documentation - - - - - - - + + + + + + - - -- - -
--- + -The Travis API
-All the routes, just waiting for you to build something awesome.
-++-++The Travis API
+All the routes, just waiting for you to build something awesome.
+