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

This commit is contained in:
Konstantin Haase 2013-01-28 15:44:04 +01:00
commit 18b9739691
21 changed files with 106 additions and 63 deletions

View File

@ -3,8 +3,8 @@ ruby '1.9.3' rescue nil
source :rubygems source :rubygems
gemspec gemspec
gem 'travis-support', github: 'travis-ci/travis-support'
gem 'travis-core', github: 'travis-ci/travis-core' 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 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741'
gem 'sinatra' #github: 'sinatra/sinatra' gem 'sinatra' #github: 'sinatra/sinatra'
gem 'sinatra-contrib', require: nil #github: 'sinatra/sinatra-contrib', require: nil gem 'sinatra-contrib', require: nil #github: 'sinatra/sinatra-contrib', require: nil
@ -38,5 +38,5 @@ end
group :development, :test do group :development, :test do
gem 'rake', '~> 0.9.2' 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 end

View File

@ -45,7 +45,7 @@ GIT
GIT GIT
remote: git://github.com/travis-ci/travis-core.git remote: git://github.com/travis-ci/travis-core.git
revision: ba4e4a83b473393539728a3aeb8e3499ab1ef1bc revision: 2d766c54c2fea70dfc4d937c22413eee937f002b
specs: specs:
travis-core (0.0.1) travis-core (0.0.1)
actionmailer (~> 3.2.11) actionmailer (~> 3.2.11)
@ -59,7 +59,7 @@ GIT
postmark-rails (~> 0.4.1) postmark-rails (~> 0.4.1)
pusher (~> 0.11.0) pusher (~> 0.11.0)
railties (~> 3.2.11) railties (~> 3.2.11)
rake (~> 0.9.2.2) rake
redis (~> 3.0) redis (~> 3.0)
rollout (~> 1.1.0) rollout (~> 1.1.0)
simple_states (~> 0.1.1) simple_states (~> 0.1.1)
@ -75,12 +75,12 @@ GIT
GIT GIT
remote: git://github.com/travis-ci/travis-support.git remote: git://github.com/travis-ci/travis-support.git
revision: a288008629ae7eab18c529008880d364daca82ce revision: ff712aca1083a588974f835a84c574e6976aeb29
specs: specs:
travis-support (0.0.1) travis-support (0.0.1)
GIT GIT
remote: http://gist.github.com/4269321.git remote: https://gist.github.com/4269321.git
revision: 8e2d21b924a69dd48191df6a18e51769f5a88614 revision: 8e2d21b924a69dd48191df6a18e51769f5a88614
specs: specs:
micro_migrations (0.0.1) micro_migrations (0.0.1)
@ -143,7 +143,7 @@ GEM
coderay (1.0.8) coderay (1.0.8)
connection_pool (0.9.3) connection_pool (0.9.3)
daemons (1.1.9) daemons (1.1.9)
dalli (2.6.0) dalli (2.6.2)
data_migrations (0.0.1) data_migrations (0.0.1)
activerecord activerecord
rake rake
@ -185,7 +185,7 @@ GEM
multipart-post (1.1.5) multipart-post (1.1.5)
net-http-persistent (2.8) net-http-persistent (2.8)
net-http-pipeline (1.0.1) net-http-pipeline (1.0.1)
newrelic_rpm (3.5.5.38) newrelic_rpm (3.5.6.46)
pg (0.13.2) pg (0.13.2)
polyglot (0.3.3) polyglot (0.3.3)
postmark (0.9.18) postmark (0.9.18)
@ -220,7 +220,7 @@ GEM
rake (>= 0.8.7) rake (>= 0.8.7)
rdoc (~> 3.4) rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0) thor (>= 0.14.6, < 2.0)
rake (0.9.2.2) rake (0.9.6)
rdoc (3.12) rdoc (3.12)
json (~> 1.4) json (~> 1.4)
redcarpet (2.2.2) redcarpet (2.2.2)

View File

@ -111,16 +111,19 @@ module Travis::Api
Travis::Amqp.config = Travis.config.amqp Travis::Amqp.config = Travis.config.amqp
Travis::Database.connect Travis::Database.connect
Travis::Features.start 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'
Sidekiq.configure_client do |config|
config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace)
end
Raven.configure do |config|
config.dsn = Travis.config.sentry.dsn
end if Travis.config.sentry
Travis::LogSubscriber::ActiveRecordMetrics.attach
Travis::Notification.setup
end end
Raven.configure do |config|
config.dsn = Travis.config.sentry.dsn
end if Travis.config.sentry
Travis::LogSubscriber::ActiveRecordMetrics.attach
Travis::Notification.setup
end end
def self.load_endpoints def self.load_endpoints

View File

@ -9,6 +9,12 @@ class Travis::Api::App
get '/:id' do |id| get '/:id' do |id|
respond_with service(:find_artifact, params) respond_with service(:find_artifact, params)
end end
# TODO needs auth, required for live log archiving on log:aggregted in travis-tasks
#
# put '/:id' do |id|
# respond_with service(:update_artifact, params)
# end
end end
end end
end end

View File

@ -4,7 +4,8 @@ class Travis::Api::App
class Endpoint class Endpoint
class Builds < Endpoint class Builds < Endpoint
get '/' do get '/' do
respond_with service(:find_builds, params) name = params[:branches] ? :find_branches : :find_builds
respond_with service(name, params)
end end
get '/:id' do get '/:id' do

View File

@ -10,6 +10,23 @@ class Travis::Api::App
get '/:id' do get '/:id' do
respond_with service(:find_job, params) respond_with service(:find_job, params)
end end
get '/:job_id/log' do
resource = service(:find_artifact, params).run
if !resource || resource.archived?
redirect archive_url("/jobs/#{params[:job_id]}/log.txt")
else
respond_with resource
end
end
def archive_url(path)
"https://s3.amazonaws.com/#{hostname('archive')}#{path}"
end
def hostname(name)
"#{name}#{'-staging' if Travis.env == 'staging'}.#{Travis.config.host.split('.')[-2, 2].join('.')}"
end
end end
end end
end end

View File

@ -1,8 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'Branches' do describe 'Branches' do
before { Scenario.default }
let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } }

View File

@ -1,8 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'Builds' do describe 'Builds' do
before { Scenario.default }
let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
let(:build) { repo.builds.first } let(:build) { repo.builds.first }
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } }

View File

@ -2,7 +2,6 @@ require 'spec_helper'
describe 'Hooks' do describe 'Hooks' do
before(:each) do before(:each) do
Scenario.default
user.permissions.create repository: repo, admin: true user.permissions.create repository: repo, admin: true
end end

View File

@ -1,8 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'v1 repos' do describe 'v1 repos' do
before(:each) { Scenario.default }
let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } }

View File

@ -1,22 +1,12 @@
require 'spec_helper' require 'spec_helper'
describe 'Workers' do describe 'Workers' do
before(:each) do let!(:workers) { [Worker.create(full_name: 'one'), Worker.create(full_name: 'two')] }
Time.stubs(:now).returns(Time.utc(2011, 11, 11, 11, 11, 11)) let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } }
@workers = [
Worker.new('1', full_name: 'ruby1:ruby1.travis-ci.org'),
Worker.new('2', full_name: 'ruby2:ruby1.travis-ci.org')
]
end
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } }
attr_reader :workers
it 'GET /workers' do it 'GET /workers' do
Worker.stubs(all: @workers)
response = get '/workers', {}, headers response = get '/workers', {}, headers
response.should deliver_json_for(@workers, version: 'v1', type: 'workers') response.should deliver_json_for(Worker.all, version: 'v1', type: 'workers')
end end
end end

View File

@ -1,8 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'Branches' do describe 'Branches' do
before { Scenario.default }
let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }

View File

@ -1,8 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'Builds' do describe 'Builds' do
before { Scenario.default }
let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
let(:build) { repo.builds.first } let(:build) { repo.builds.first }
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }
@ -31,4 +29,9 @@ describe 'Builds' do
response = get "/repos/svenfuchs/minimal/builds/#{build.id}", {}, headers response = get "/repos/svenfuchs/minimal/builds/#{build.id}", {}, headers
response.should deliver_json_for(build, version: 'v2') response.should deliver_json_for(build, version: 'v2')
end end
it 'GET /builds/1?repository_id=1&branches=true' 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
end end

View File

@ -3,7 +3,6 @@ require 'travis/testing/payloads'
describe 'Hooks' do describe 'Hooks' do
before(:each) do before(:each) do
Scenario.default
user.permissions.create repository: repo, admin: true user.permissions.create repository: repo, admin: true
end end

View File

@ -13,8 +13,32 @@ describe 'Jobs' do
response.should deliver_json_for(Job.queued('builds.common'), version: 'v2') response.should deliver_json_for(Job.queued('builds.common'), version: 'v2')
end end
it '/jobs/:job_id' do it '/jobs/:id' do
response = get "/jobs/#{job.id}", {}, headers response = get "/jobs/#{job.id}", {}, headers
response.should deliver_json_for(job, version: 'v2') response.should deliver_json_for(job, version: 'v2')
end end
context 'GET /jobs/:job_id/log.txt' do
it 'returns log for a job' do
job.log.update_attributes!(content: 'the log')
response = get "/jobs/#{job.id}/log.txt", {}, headers
response.should deliver_as_txt('the log', version: 'v2')
end
context 'when log is archived' do
it 'redirects to archive' do
job.log.update_attributes!(content: 'the log', archived_at: Time.now, archive_verified: true)
response = get "/jobs/#{job.id}/log.txt", {}, headers
response.should redirect_to("https://s3.amazonaws.com/archive.travis-ci.org/jobs/#{job.id}/log.txt")
end
end
context 'when log is missing' do
it 'redirects to archive' do
job.log.destroy
response = get "/jobs/#{job.id}/log.txt", {}, headers
response.should redirect_to("https://s3.amazonaws.com/archive.travis-ci.org/jobs/#{job.id}/log.txt")
end
end
end
end end

View File

@ -1,8 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'Repos' do describe 'Repos' do
before(:each) { Scenario.default }
let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'Users' do describe 'Users' do
let(:user) { Factory(:user, locale: 'en') } let(:user) { User.first }
let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) } let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) }
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json', 'HTTP_AUTHORIZATION' => "token #{token}" } } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json', 'HTTP_AUTHORIZATION' => "token #{token}" } }

View File

@ -1,22 +1,12 @@
require 'spec_helper' require 'spec_helper'
describe 'Workers' do describe 'Workers' do
before(:each) do let!(:workers) { [Worker.create(full_name: 'one'), Worker.create(full_name: 'two')] }
Time.stubs(:now).returns(Time.utc(2011, 11, 11, 11, 11, 11)) let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }
@workers = [
Worker.new('1', full_name: 'ruby1:ruby1.travis-ci.org'),
Worker.new('2', full_name: 'ruby2:ruby1.travis-ci.org')
]
end
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }
attr_reader :workers
it 'GET /workers' do it 'GET /workers' do
Worker.stubs(all: @workers)
response = get '/workers', {}, headers response = get '/workers', {}, headers
response.should deliver_json_for(@workers, version: 'v2', type: 'workers') response.should deliver_json_for(Worker.all, version: 'v2', type: 'workers')
end end
end end

View File

@ -41,7 +41,8 @@ RSpec.configure do |c|
c.before :suite do c.before :suite do
DatabaseCleaner.strategy = :transaction DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with :transaction DatabaseCleaner.clean_with :truncation
Scenario.default
end end
c.before :each do c.before :each do

View File

@ -24,6 +24,26 @@ RSpec::Matchers.define :deliver_json_for do |resource, options = {}|
end end
end end
RSpec::Matchers.define :deliver_as_txt do |expected, options = {}|
match do |response|
if response.status == 200
failure_message_for_should do
"expected\n\n#{actual}\n\nto equal\n\n#{expected}"
end
response.body.to_s == expected
else
failure_message_for_should do
"expected the request to be successful (200) but was #{response.status}"
end
false
end
end
def parse(body)
MultiJson.decode(body)
end
end
RSpec::Matchers.define :deliver_result_image_for do |name| RSpec::Matchers.define :deliver_result_image_for do |name|
match do |response| match do |response|
header = response.headers['content-disposition'] header = response.headers['content-disposition']

View File

@ -18,7 +18,7 @@ describe Travis::Api::App::Endpoint::Accounts do
'login' => user.login, 'login' => user.login,
'name' => user.name, 'name' => user.name,
'type' => 'user', 'type' => 'user',
'repos_count' => nil 'repos_count' => 1
}] }]
end end
end end