travis-api/lib/travis/api/app/endpoint/jobs.rb
2013-07-10 16:55:03 -07:00

57 lines
1.4 KiB
Ruby

require 'travis/api/app'
class Travis::Api::App
class Endpoint
class Jobs < Endpoint
get '/' do
respond_with service(:find_jobs, params)
end
get '/:id' do
respond_with service(:find_job, params)
end
get '/:job_id/log' do
resource = service(:find_log, params).run
if !resource || resource.archived?
archived_log_path = archive_url("/jobs/#{params[:job_id]}/log.txt")
if params[:cors_hax]
status 204
headers['Access-Control-Expose-Headers'] = 'Location'
headers['Location'] = archived_log_path
else
redirect archived_log_path, 307
end
else
respond_with resource
end
end
get "/:job_id/annotations" do
respond_with service(:find_annotations, params)
end
post "/:job_id/annotations" do
if params[:description]
annotation = service(:update_annotation, params).run
status annotation ? 204 : 401
else
status 422
{ "error" => "Must include a description" }
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