Merge branch 'master' of github.com:travis-ci/travis-api
This commit is contained in:
commit
18b9739691
4
Gemfile
4
Gemfile
|
@ -3,8 +3,8 @@ ruby '1.9.3' rescue nil
|
|||
source :rubygems
|
||||
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', require: nil #github: 'sinatra/sinatra-contrib', require: nil
|
||||
|
@ -38,5 +38,5 @@ 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
|
||||
|
|
14
Gemfile.lock
14
Gemfile.lock
|
@ -45,7 +45,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-core.git
|
||||
revision: ba4e4a83b473393539728a3aeb8e3499ab1ef1bc
|
||||
revision: 2d766c54c2fea70dfc4d937c22413eee937f002b
|
||||
specs:
|
||||
travis-core (0.0.1)
|
||||
actionmailer (~> 3.2.11)
|
||||
|
@ -59,7 +59,7 @@ GIT
|
|||
postmark-rails (~> 0.4.1)
|
||||
pusher (~> 0.11.0)
|
||||
railties (~> 3.2.11)
|
||||
rake (~> 0.9.2.2)
|
||||
rake
|
||||
redis (~> 3.0)
|
||||
rollout (~> 1.1.0)
|
||||
simple_states (~> 0.1.1)
|
||||
|
@ -75,12 +75,12 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-support.git
|
||||
revision: a288008629ae7eab18c529008880d364daca82ce
|
||||
revision: ff712aca1083a588974f835a84c574e6976aeb29
|
||||
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)
|
||||
|
@ -143,7 +143,7 @@ GEM
|
|||
coderay (1.0.8)
|
||||
connection_pool (0.9.3)
|
||||
daemons (1.1.9)
|
||||
dalli (2.6.0)
|
||||
dalli (2.6.2)
|
||||
data_migrations (0.0.1)
|
||||
activerecord
|
||||
rake
|
||||
|
@ -185,7 +185,7 @@ GEM
|
|||
multipart-post (1.1.5)
|
||||
net-http-persistent (2.8)
|
||||
net-http-pipeline (1.0.1)
|
||||
newrelic_rpm (3.5.5.38)
|
||||
newrelic_rpm (3.5.6.46)
|
||||
pg (0.13.2)
|
||||
polyglot (0.3.3)
|
||||
postmark (0.9.18)
|
||||
|
@ -220,7 +220,7 @@ GEM
|
|||
rake (>= 0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
thor (>= 0.14.6, < 2.0)
|
||||
rake (0.9.2.2)
|
||||
rake (0.9.6)
|
||||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
redcarpet (2.2.2)
|
||||
|
|
|
@ -111,16 +111,19 @@ module Travis::Api
|
|||
Travis::Amqp.config = Travis.config.amqp
|
||||
Travis::Database.connect
|
||||
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
|
||||
|
||||
Raven.configure do |config|
|
||||
config.dsn = Travis.config.sentry.dsn
|
||||
end if Travis.config.sentry
|
||||
|
||||
Travis::LogSubscriber::ActiveRecordMetrics.attach
|
||||
Travis::Notification.setup
|
||||
end
|
||||
|
||||
def self.load_endpoints
|
||||
|
|
|
@ -9,6 +9,12 @@ class Travis::Api::App
|
|||
get '/:id' do |id|
|
||||
respond_with service(:find_artifact, params)
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -10,6 +10,23 @@ class Travis::Api::App
|
|||
get '/:id' do
|
||||
respond_with service(:find_job, params)
|
||||
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
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Branches' do
|
||||
before { Scenario.default }
|
||||
|
||||
let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
|
||||
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } }
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Builds' do
|
||||
before { Scenario.default }
|
||||
|
||||
let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
|
||||
let(:build) { repo.builds.first }
|
||||
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } }
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'spec_helper'
|
|||
|
||||
describe 'Hooks' do
|
||||
before(:each) do
|
||||
Scenario.default
|
||||
user.permissions.create repository: repo, admin: true
|
||||
end
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'v1 repos' do
|
||||
before(:each) { Scenario.default }
|
||||
|
||||
let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
|
||||
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } }
|
||||
|
||||
|
|
|
@ -1,22 +1,12 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Workers' do
|
||||
before(:each) do
|
||||
Time.stubs(:now).returns(Time.utc(2011, 11, 11, 11, 11, 11))
|
||||
@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
|
||||
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
|
||||
Worker.stubs(all: @workers)
|
||||
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
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Branches' do
|
||||
before { Scenario.default }
|
||||
|
||||
let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
|
||||
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Builds' do
|
||||
before { Scenario.default }
|
||||
|
||||
let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
|
||||
let(:build) { repo.builds.first }
|
||||
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.should deliver_json_for(build, version: 'v2')
|
||||
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
|
||||
|
|
|
@ -3,7 +3,6 @@ require 'travis/testing/payloads'
|
|||
|
||||
describe 'Hooks' do
|
||||
before(:each) do
|
||||
Scenario.default
|
||||
user.permissions.create repository: repo, admin: true
|
||||
end
|
||||
|
||||
|
|
|
@ -13,8 +13,32 @@ describe 'Jobs' do
|
|||
response.should deliver_json_for(Job.queued('builds.common'), version: 'v2')
|
||||
end
|
||||
|
||||
it '/jobs/:job_id' do
|
||||
it '/jobs/:id' do
|
||||
response = get "/jobs/#{job.id}", {}, headers
|
||||
response.should deliver_json_for(job, version: 'v2')
|
||||
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
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Repos' do
|
||||
before(:each) { Scenario.default }
|
||||
|
||||
let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
|
||||
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
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(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json', 'HTTP_AUTHORIZATION' => "token #{token}" } }
|
||||
|
||||
|
|
|
@ -1,22 +1,12 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Workers' do
|
||||
before(:each) do
|
||||
Time.stubs(:now).returns(Time.utc(2011, 11, 11, 11, 11, 11))
|
||||
@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
|
||||
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
|
||||
Worker.stubs(all: @workers)
|
||||
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
|
||||
|
||||
|
|
|
@ -41,7 +41,8 @@ RSpec.configure do |c|
|
|||
|
||||
c.before :suite do
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
DatabaseCleaner.clean_with :transaction
|
||||
DatabaseCleaner.clean_with :truncation
|
||||
Scenario.default
|
||||
end
|
||||
|
||||
c.before :each do
|
||||
|
|
|
@ -24,6 +24,26 @@ RSpec::Matchers.define :deliver_json_for do |resource, options = {}|
|
|||
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|
|
||||
match do |response|
|
||||
header = response.headers['content-disposition']
|
||||
|
|
|
@ -18,7 +18,7 @@ describe Travis::Api::App::Endpoint::Accounts do
|
|||
'login' => user.login,
|
||||
'name' => user.name,
|
||||
'type' => 'user',
|
||||
'repos_count' => nil
|
||||
'repos_count' => 1
|
||||
}]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user