Return log with chunks if chunked response is requested for removed log
This commit is contained in:
parent
43e20332cf
commit
6846d2f783
|
@ -59,7 +59,7 @@ class Travis::Api::App
|
|||
get '/:job_id/log' do
|
||||
resource = service(:find_log, params).run
|
||||
if (resource && resource.removed_at) && accepts?('application/json')
|
||||
respond_with resource, type: 'removed_log', root: 'log'
|
||||
respond_with resource
|
||||
elsif (!resource || resource.archived?)
|
||||
# the way we use responders makes it hard to validate proper format
|
||||
# automatically here, so we need to check it explicitly
|
||||
|
|
|
@ -16,7 +16,6 @@ module Travis
|
|||
require 'travis/api/v2/http/job'
|
||||
require 'travis/api/v2/http/jobs'
|
||||
require 'travis/api/v2/http/log'
|
||||
require 'travis/api/v2/http/removed_log'
|
||||
require 'travis/api/v2/http/permissions'
|
||||
require 'travis/api/v2/http/repositories'
|
||||
require 'travis/api/v2/http/repository'
|
||||
|
|
|
@ -11,8 +11,14 @@ module Travis
|
|||
end
|
||||
|
||||
def data
|
||||
log_hash = options[:chunked] ? chunked_log_data : log_data
|
||||
if log.removed_at
|
||||
log_hash['removed_at'] = log.removed_at
|
||||
log_hash['removed_by'] = log.removed_by.name || object.removed_by.login
|
||||
end
|
||||
|
||||
{
|
||||
'log' => options[:chunked] ? chunked_log_data : log_data,
|
||||
'log' => log_hash,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -37,6 +43,10 @@ module Travis
|
|||
end
|
||||
|
||||
def log_parts
|
||||
if log.removed_at
|
||||
# if log is removed we don't have actual parts
|
||||
parts = [{ 'number' => 1, 'content' => log.content, 'final' => true }]
|
||||
else
|
||||
parts = log.parts
|
||||
parts = parts.where(number: part_numbers) if part_numbers
|
||||
parts = parts.where(["number > ?", after]) if after
|
||||
|
@ -49,6 +59,7 @@ module Travis
|
|||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def after
|
||||
after = options['after'].to_i
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
module Travis
|
||||
module Api
|
||||
module V2
|
||||
module Http
|
||||
class RemovedLog < Travis::Api::Serializer
|
||||
attributes :id, :job_id, :body, :removed_at, :removed_by
|
||||
|
||||
def body
|
||||
object.content
|
||||
end
|
||||
|
||||
def removed_by
|
||||
object.removed_by.name || object.removed_by.login if object.removed_by
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -107,13 +107,16 @@ describe 'Jobs' do
|
|||
it 'adds removed info if the log is removed' do
|
||||
time = Time.new(2015, 1, 9, 12, 57, 31)
|
||||
job.log.update_attributes(removed_at: time, removed_by: User.first)
|
||||
headers = { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' }
|
||||
headers = { 'HTTP_ACCEPT' => 'application/json; chunked=true; version=2' }
|
||||
response = get "/jobs/#{job.id}/log", {}, headers
|
||||
body = JSON.parse(response.body)
|
||||
|
||||
body['log']['removed_by'].should == 'Sven Fuchs'
|
||||
body['log']['removed_at'].should == "2015-01-09T11:57:31Z"
|
||||
body['log']['id'].should == job.log.id
|
||||
|
||||
# make sure we return parts as chunked=true
|
||||
body['log']['parts'].length.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user