Revert "Merge branch 'master' of github.com:travis-ci/travis-api"
This reverts commit1b8f77ab36
, reversing changes made to79a4a9ad13
.
This commit is contained in:
parent
1b8f77ab36
commit
171b9c57c7
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ log/
|
||||||
vendor
|
vendor
|
||||||
config/skylight.yml
|
config/skylight.yml
|
||||||
.coverage
|
.coverage
|
||||||
|
.coverage/
|
||||||
|
|
2
Gemfile
2
Gemfile
|
@ -8,7 +8,7 @@ gem 's3', github: 'travis-ci/s3'
|
||||||
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-support', github: 'travis-ci/travis-support'
|
||||||
gem 'travis-config', '~> 0.1.0'
|
gem 'travis-config', '~> 0.1.0'
|
||||||
gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil
|
gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741'
|
||||||
gem 'travis-yaml', github: 'travis-ci/travis-yaml'
|
gem 'travis-yaml', github: 'travis-ci/travis-yaml'
|
||||||
gem 'mustermann', github: 'rkh/mustermann'
|
gem 'mustermann', github: 'rkh/mustermann'
|
||||||
gem 'sinatra'
|
gem 'sinatra'
|
||||||
|
|
43
Gemfile.lock
43
Gemfile.lock
|
@ -74,10 +74,11 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-sidekiqs.git
|
remote: git://github.com/travis-ci/travis-sidekiqs.git
|
||||||
revision: 21a2fee158e25252dd78f5fa31e81b4f6583be23
|
revision: cde9741f8e6811fe3929bdd0dd653b87289c5eef
|
||||||
|
ref: cde9741
|
||||||
specs:
|
specs:
|
||||||
travis-sidekiqs (0.0.1)
|
travis-sidekiqs (0.0.1)
|
||||||
sidekiq
|
sidekiq (~> 2.5.0)
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-support.git
|
remote: git://github.com/travis-ci/travis-support.git
|
||||||
|
@ -148,13 +149,26 @@ GEM
|
||||||
backports (3.6.4)
|
backports (3.6.4)
|
||||||
builder (3.0.4)
|
builder (3.0.4)
|
||||||
bunny (0.8.0)
|
bunny (0.8.0)
|
||||||
celluloid (0.16.0)
|
celluloid (0.12.0)
|
||||||
timers (~> 4.0.0)
|
timers (>= 1.0.0)
|
||||||
|
chunky_png (1.3.3)
|
||||||
coder (0.4.0)
|
coder (0.4.0)
|
||||||
coderay (1.1.0)
|
coderay (1.1.0)
|
||||||
coercible (1.0.0)
|
coercible (1.0.0)
|
||||||
descendants_tracker (~> 0.0.1)
|
descendants_tracker (~> 0.0.1)
|
||||||
connection_pool (2.1.1)
|
compass (1.0.1)
|
||||||
|
chunky_png (~> 1.2)
|
||||||
|
compass-core (~> 1.0.1)
|
||||||
|
compass-import-once (~> 1.0.5)
|
||||||
|
rb-fsevent (>= 0.9.3)
|
||||||
|
rb-inotify (>= 0.9)
|
||||||
|
sass (>= 3.3.13, < 3.5)
|
||||||
|
compass-core (1.0.1)
|
||||||
|
multi_json (~> 1.0)
|
||||||
|
sass (>= 3.3.0, < 3.5)
|
||||||
|
compass-import-once (1.0.5)
|
||||||
|
sass (>= 3.2, < 3.5)
|
||||||
|
connection_pool (0.9.3)
|
||||||
daemons (1.1.9)
|
daemons (1.1.9)
|
||||||
dalli (2.7.2)
|
dalli (2.7.2)
|
||||||
data_migrations (0.0.1)
|
data_migrations (0.0.1)
|
||||||
|
@ -268,12 +282,16 @@ GEM
|
||||||
rspec-expectations (2.99.2)
|
rspec-expectations (2.99.2)
|
||||||
diff-lcs (>= 1.1.3, < 2.0)
|
diff-lcs (>= 1.1.3, < 2.0)
|
||||||
rspec-mocks (2.99.2)
|
rspec-mocks (2.99.2)
|
||||||
sidekiq (3.3.0)
|
sass (3.4.6)
|
||||||
celluloid (>= 0.16.0)
|
sidekiq (2.5.0)
|
||||||
connection_pool (>= 2.0.0)
|
celluloid (~> 0.12.0)
|
||||||
json
|
compass
|
||||||
redis (>= 3.0.6)
|
connection_pool (~> 0.9.2)
|
||||||
redis-namespace (>= 1.3.1)
|
multi_json (~> 1)
|
||||||
|
redis (~> 3)
|
||||||
|
redis-namespace
|
||||||
|
sass
|
||||||
|
sprockets-sass
|
||||||
signature (0.1.7)
|
signature (0.1.7)
|
||||||
simple_states (1.0.1)
|
simple_states (1.0.1)
|
||||||
activesupport
|
activesupport
|
||||||
|
@ -302,6 +320,9 @@ GEM
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
tilt (~> 1.1, != 1.3.0)
|
tilt (~> 1.1, != 1.3.0)
|
||||||
|
sprockets-sass (1.2.0)
|
||||||
|
sprockets (~> 2.0)
|
||||||
|
tilt (~> 1.1)
|
||||||
thin (1.6.3)
|
thin (1.6.3)
|
||||||
daemons (~> 1.0, >= 1.0.9)
|
daemons (~> 1.0, >= 1.0.9)
|
||||||
eventmachine (~> 1.0)
|
eventmachine (~> 1.0)
|
||||||
|
|
1
Procfile
1
Procfile
|
@ -1,3 +1,2 @@
|
||||||
web: bundle exec ./script/server
|
web: bundle exec ./script/server
|
||||||
console: bundle exec ./script/console
|
console: bundle exec ./script/console
|
||||||
sidekiq: bundle exec sidekiq -c 5 -r ./lib/travis/sidekiq.rb -q build_cancellations, -q build_restarts, -q job_cancellations, -q job_restarts
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
require 'travis/api/app'
|
require 'travis/api/app'
|
||||||
require 'travis/api/workers/build_cancellation'
|
|
||||||
require 'travis/api/workers/build_restart'
|
|
||||||
|
|
||||||
class Travis::Api::App
|
class Travis::Api::App
|
||||||
class Endpoint
|
class Endpoint
|
||||||
|
@ -39,7 +37,7 @@ class Travis::Api::App
|
||||||
status 422
|
status 422
|
||||||
respond_with json
|
respond_with json
|
||||||
else
|
else
|
||||||
Travis::Sidekiq::BuildCancellation.perform_async(id: params[:id], user_id: current_user.id, source: 'api')
|
service.run
|
||||||
|
|
||||||
Metriks.meter("api.request.cancel_build.success").mark
|
Metriks.meter("api.request.cancel_build.success").mark
|
||||||
status 204
|
status 204
|
||||||
|
@ -48,17 +46,7 @@ class Travis::Api::App
|
||||||
|
|
||||||
post '/:id/restart' do
|
post '/:id/restart' do
|
||||||
Metriks.meter("api.request.restart_build").mark
|
Metriks.meter("api.request.restart_build").mark
|
||||||
|
respond_with service(:reset_model, build_id: params[:id])
|
||||||
service = self.service(:reset_model, build_id: params[:id])
|
|
||||||
if !service.accept?
|
|
||||||
status 400
|
|
||||||
result = false
|
|
||||||
else
|
|
||||||
Travis::Sidekiq::BuildRestart.perform_async(id: params[:id], user_id: current_user.id)
|
|
||||||
status 202
|
|
||||||
result = true
|
|
||||||
end
|
|
||||||
respond_with(result: result, flash: service.messages)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
require 'travis/api/app'
|
require 'travis/api/app'
|
||||||
require 'travis/api/workers/job_cancellation'
|
|
||||||
require 'travis/api/workers/job_restart'
|
|
||||||
|
|
||||||
class Travis::Api::App
|
class Travis::Api::App
|
||||||
class Endpoint
|
class Endpoint
|
||||||
|
@ -46,7 +44,7 @@ class Travis::Api::App
|
||||||
status 422
|
status 422
|
||||||
respond_with json
|
respond_with json
|
||||||
else
|
else
|
||||||
Travis::Sidekiq::JobCancellation.perform_async(id: params[:id], user_id: current_user.id, source: 'api')
|
service.run
|
||||||
|
|
||||||
Metriks.meter("api.request.cancel_job.success").mark
|
Metriks.meter("api.request.cancel_job.success").mark
|
||||||
status 204
|
status 204
|
||||||
|
@ -55,17 +53,7 @@ class Travis::Api::App
|
||||||
|
|
||||||
post '/:id/restart' do
|
post '/:id/restart' do
|
||||||
Metriks.meter("api.request.restart_job").mark
|
Metriks.meter("api.request.restart_job").mark
|
||||||
|
respond_with service(:reset_model, job_id: params[:id])
|
||||||
service = self.service(:reset_model, job_id: params[:id])
|
|
||||||
if !service.accept?
|
|
||||||
status 400
|
|
||||||
result = false
|
|
||||||
else
|
|
||||||
Travis::Sidekiq::JobRestart.perform_async(id: params[:id], user_id: current_user.id)
|
|
||||||
status 202
|
|
||||||
result = true
|
|
||||||
end
|
|
||||||
respond_with(result: result, flash: service.messages)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/:job_id/log' do
|
get '/:job_id/log' do
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
require 'sidekiq/worker'
|
|
||||||
require 'multi_json'
|
|
||||||
|
|
||||||
module Travis
|
|
||||||
module Sidekiq
|
|
||||||
class BuildCancellation
|
|
||||||
class ProcessingError < StandardError; end
|
|
||||||
|
|
||||||
include ::Sidekiq::Worker
|
|
||||||
sidekiq_options queue: :build_cancellations
|
|
||||||
|
|
||||||
def perform(data)
|
|
||||||
user = User.find(data['user_id'])
|
|
||||||
Travis.service(:cancel_build, user, { id: data['id'], source: data['source'] }).run
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,19 +0,0 @@
|
||||||
require 'sidekiq/worker'
|
|
||||||
require 'multi_json'
|
|
||||||
|
|
||||||
module Travis
|
|
||||||
module Sidekiq
|
|
||||||
class BuildRestart
|
|
||||||
class ProcessingError < StandardError; end
|
|
||||||
|
|
||||||
include ::Sidekiq::Worker
|
|
||||||
sidekiq_options queue: :build_restarts
|
|
||||||
|
|
||||||
def perform(data)
|
|
||||||
user = User.find(data['user_id'])
|
|
||||||
Travis.service(:reset_model, user, build_id: data['id']).run
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,19 +0,0 @@
|
||||||
require 'sidekiq/worker'
|
|
||||||
require 'multi_json'
|
|
||||||
|
|
||||||
module Travis
|
|
||||||
module Sidekiq
|
|
||||||
class JobCancellation
|
|
||||||
class ProcessingError < StandardError; end
|
|
||||||
|
|
||||||
include ::Sidekiq::Worker
|
|
||||||
sidekiq_options queue: :job_cancellations
|
|
||||||
|
|
||||||
def perform(data)
|
|
||||||
user = User.find(data['user_id'])
|
|
||||||
Travis.service(:cancel_job, user, { id: data['id'], source: data['source'] }).run
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,19 +0,0 @@
|
||||||
require 'sidekiq/worker'
|
|
||||||
require 'multi_json'
|
|
||||||
|
|
||||||
module Travis
|
|
||||||
module Sidekiq
|
|
||||||
class JobRestart
|
|
||||||
class ProcessingError < StandardError; end
|
|
||||||
|
|
||||||
include ::Sidekiq::Worker
|
|
||||||
sidekiq_options queue: :job_restarts
|
|
||||||
|
|
||||||
def perform(data)
|
|
||||||
user = User.find(data['user_id'])
|
|
||||||
Travis.service(:reset_model, user, job_id: data['id']).run
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,22 +0,0 @@
|
||||||
#$: << './lib'
|
|
||||||
require 'sidekiq'
|
|
||||||
require 'travis'
|
|
||||||
require 'travis/api/workers/build_cancellation'
|
|
||||||
require 'travis/api/workers/build_restart'
|
|
||||||
require 'travis/api/workers/job_cancellation'
|
|
||||||
require 'travis/api/workers/job_restart'
|
|
||||||
require 'travis/support/amqp'
|
|
||||||
|
|
||||||
Travis::Database.connect
|
|
||||||
Travis::Async.enabled = true
|
|
||||||
Travis::Amqp.config = Travis.config.amqp
|
|
||||||
Travis::Metrics.setup
|
|
||||||
Travis::Notification.setup
|
|
||||||
|
|
||||||
Sidekiq.configure_server do |config|
|
|
||||||
config.redis = Travis.config.redis.merge(namespace: Travis.config.sidekiq.namespace)
|
|
||||||
end
|
|
||||||
|
|
||||||
Sidekiq.configure_client do |config|
|
|
||||||
config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace)
|
|
||||||
end
|
|
|
@ -75,60 +75,17 @@ describe 'Builds' do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when build can be canceled' do
|
context 'when build can be canceled' do
|
||||||
before do
|
it 'cancels the build and responds with 204' do
|
||||||
Travis::Sidekiq::BuildCancellation.stubs(:perform_async)
|
|
||||||
build.matrix.each { |j| j.update_attribute(:state, 'created') }
|
build.matrix.each { |j| j.update_attribute(:state, 'created') }
|
||||||
build.update_attribute(:state, 'created')
|
build.update_attribute(:state, 'created')
|
||||||
end
|
|
||||||
|
|
||||||
it 'cancels the build' do
|
response = nil
|
||||||
Travis::Sidekiq::BuildCancellation.expects(:perform_async).with( id: build.id.to_s, user_id: user.id, source: 'api')
|
expect {
|
||||||
post "/builds/#{build.id}/cancel", {}, headers
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'responds with 204' do
|
|
||||||
response = post "/builds/#{build.id}/cancel", {}, headers
|
response = post "/builds/#{build.id}/cancel", {}, headers
|
||||||
|
}.to change { build.reload.state }
|
||||||
response.status.should == 204
|
response.status.should == 204
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'POST /builds/:id/restart' do
|
build.state.should == 'canceled'
|
||||||
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, :pull => true, :push => true)
|
|
||||||
}
|
|
||||||
|
|
||||||
context 'when restart is not acceptable' do
|
|
||||||
before { user.permissions.destroy_all }
|
|
||||||
|
|
||||||
it 'responds with 400' do
|
|
||||||
response = post "/builds/#{build.id}/restart", {}, headers
|
|
||||||
response.status.should == 400
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when build passed' do
|
|
||||||
before do
|
|
||||||
Travis::Sidekiq::BuildCancellation.stubs(:perform_async)
|
|
||||||
build.matrix.each { |j| j.update_attribute(:state, 'passed') }
|
|
||||||
build.update_attribute(:state, 'passed')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'restarts the build' do
|
|
||||||
Travis::Sidekiq::BuildRestart.expects(:perform_async).with(id: build.id.to_s, user_id: user.id)
|
|
||||||
response = post "/builds/#{build.id}/restart", {}, headers
|
|
||||||
response.status.should == 202
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'sends the correct response body' do
|
|
||||||
Travis::Sidekiq::BuildRestart.expects(:perform_async).with(id: build.id.to_s, user_id: user.id)
|
|
||||||
response = post "/builds/#{build.id}/restart", {}, headers
|
|
||||||
body = JSON.parse(response.body)
|
|
||||||
body.should == {"result"=>true, "flash"=>[{"notice"=>"The build was successfully restarted."}]}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -242,56 +242,16 @@ describe 'Jobs' do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when job can be canceled' do
|
context 'when job can be canceled' do
|
||||||
before do
|
it 'cancels the job and responds with 204' do
|
||||||
job.update_attribute(:state, 'created')
|
job.update_attribute(:state, 'created')
|
||||||
end
|
|
||||||
|
|
||||||
it 'cancels the job' do
|
response = nil
|
||||||
Travis::Sidekiq::JobCancellation.expects(:perform_async).with( id: job.id.to_s, user_id: user.id, source: 'api')
|
expect {
|
||||||
post "/jobs/#{job.id}/cancel", {}, headers
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'responds with 204' do
|
|
||||||
response = post "/jobs/#{job.id}/cancel", {}, headers
|
response = post "/jobs/#{job.id}/cancel", {}, headers
|
||||||
|
}.to change { job.reload.state }
|
||||||
response.status.should == 204
|
response.status.should == 204
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'POST /jobs/:id/restart' do
|
job.state.should == 'canceled'
|
||||||
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, :pull => true, :push => true)
|
|
||||||
}
|
|
||||||
|
|
||||||
context 'when restart is not acceptable' do
|
|
||||||
before { user.permissions.destroy_all }
|
|
||||||
|
|
||||||
it 'responds with 400' do
|
|
||||||
response = post "/jobs/#{job.id}/restart", {}, headers
|
|
||||||
response.status.should == 400
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when job passed' do
|
|
||||||
before do
|
|
||||||
Travis::Sidekiq::JobCancellation.stubs(:perform_async)
|
|
||||||
job.update_attribute(:state, 'passed')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'restarts the job' do
|
|
||||||
Travis::Sidekiq::JobRestart.expects(:perform_async).with(id: job.id.to_s, user_id: user.id)
|
|
||||||
response = post "/jobs/#{job.id}/restart", {}, headers
|
|
||||||
response.status.should == 202
|
|
||||||
end
|
|
||||||
it 'sends the correct response body' do
|
|
||||||
Travis::Sidekiq::JobRestart.expects(:perform_async).with(id: job.id.to_s, user_id: user.id)
|
|
||||||
response = post "/jobs/#{job.id}/restart", {}, headers
|
|
||||||
body = JSON.parse(response.body)
|
|
||||||
body.should == {"result"=>true, "flash"=>[{"notice"=>"The job was successfully restarted."}]}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user