
: add require sidekiq to the sidekiq.rb update Gemfile.lock bump travis-sidekiqs correct require statement fix another request connect to the database add current user add current user correctly add current user correctly add puts to see were in the condition we are missing invertted comma add comments to the worker I HAVE NO IDEA Revert "I HAVE NO IDEA" This reverts commit 8bd1259bf4ea1b479f9391847a4700b7b15efe57. change the id and source to symbols in the params because siedekiq expects that add more printout setup database connection, metrics and notification correct the test
57 lines
1.7 KiB
Ruby
57 lines
1.7 KiB
Ruby
require 'travis/api/app'
|
|
require 'travis/api/workers/build_cancellation'
|
|
|
|
class Travis::Api::App
|
|
class Endpoint
|
|
class Builds < Endpoint
|
|
get '/' do
|
|
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
|
|
respond_with service(:find_build, params)
|
|
end
|
|
|
|
post '/:id/cancel' do
|
|
Metriks.meter("api.request.cancel_build").mark
|
|
|
|
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]})"
|
|
} }
|
|
|
|
Metriks.meter("api.request.cancel_build.unauthorized").mark
|
|
status 403
|
|
respond_with json
|
|
elsif !service.can_cancel?
|
|
json = { error: {
|
|
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
|
|
#check syntax of line below
|
|
Travis::Sidekiq::BuildCancellation.perform_async(id: params[:id], user_id: current_user.id, source: 'api')
|
|
|
|
Metriks.meter("api.request.cancel_build.success").mark
|
|
status 204
|
|
end
|
|
end
|
|
|
|
post '/:id/restart' do
|
|
Metriks.meter("api.request.restart_build").mark
|
|
respond_with service(:reset_model, build_id: params[:id])
|
|
end
|
|
end
|
|
end
|
|
end
|