Return removed_at and removed_by if the log was removed

This commit is contained in:
Piotr Sarnacki 2015-01-09 13:05:31 +01:00
parent bd9714dca9
commit 43e20332cf
6 changed files with 51 additions and 5 deletions

View File

@ -34,6 +34,13 @@ GIT
rack-cache (1.2) rack-cache (1.2)
rack (>= 0.4) rack (>= 0.4)
GIT
remote: git://github.com/travis-ci/s3.git
revision: 386361c1b0ede19cde0ddaf86e41a16308575f5d
specs:
s3 (0.3.21)
proxies (~> 0.2.0)
GIT GIT
remote: git://github.com/travis-ci/travis-core.git remote: git://github.com/travis-ci/travis-core.git
revision: 8fa9680a47ab457187ddf3a88461a756a6f4c2a6 revision: 8fa9680a47ab457187ddf3a88461a756a6f4c2a6
@ -270,8 +277,6 @@ 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)
s3 (0.3.21)
proxies (~> 0.2.0)
sass (3.4.6) sass (3.4.6)
sidekiq (2.5.0) sidekiq (2.5.0)
celluloid (~> 0.12.0) celluloid (~> 0.12.0)
@ -358,6 +363,7 @@ DEPENDENCIES
rb-fsevent (~> 0.9.1) rb-fsevent (~> 0.9.1)
rerun rerun
rspec (~> 2.13) rspec (~> 2.13)
s3!
sentry-raven! sentry-raven!
sinatra sinatra
sinatra-contrib sinatra-contrib

View File

@ -58,7 +58,9 @@ class Travis::Api::App
get '/:job_id/log' do get '/:job_id/log' do
resource = service(:find_log, params).run resource = service(:find_log, params).run
if (!resource || resource.archived?) if (resource && resource.removed_at) && accepts?('application/json')
respond_with resource, type: 'removed_log', root: 'log'
elsif (!resource || resource.archived?)
# the way we use responders makes it hard to validate proper format # the way we use responders makes it hard to validate proper format
# automatically here, so we need to check it explicitly # automatically here, so we need to check it explicitly
if accepts?('text/plain') if accepts?('text/plain')

View File

@ -23,13 +23,18 @@ class Travis::Api::App
return true unless resource.is_a?(Log) return true unless resource.is_a?(Log)
chunked = accept_params[:chunked] chunked = accept_params[:chunked]
chunked ? !resource.aggregated_at : true if resource.removed_at
true
else
chunked ? !resource.aggregated_at : true
end
end end
def result def result
if builder if builder
p = params p = params
p[:root] = options[:type] if options[:type] p[:root] = options[:root] if options[:root]
p[:root] = options[:type] if options[:type] && !p[:root]
builder.new(resource, p).data builder.new(resource, p).data
else else
basic_type_resource basic_type_resource

View File

@ -16,6 +16,7 @@ module Travis
require 'travis/api/v2/http/job' require 'travis/api/v2/http/job'
require 'travis/api/v2/http/jobs' require 'travis/api/v2/http/jobs'
require 'travis/api/v2/http/log' require 'travis/api/v2/http/log'
require 'travis/api/v2/http/removed_log'
require 'travis/api/v2/http/permissions' require 'travis/api/v2/http/permissions'
require 'travis/api/v2/http/repositories' require 'travis/api/v2/http/repositories'
require 'travis/api/v2/http/repository' require 'travis/api/v2/http/repository'

View File

@ -0,0 +1,20 @@
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

View File

@ -103,6 +103,18 @@ describe 'Jobs' do
response.should deliver_json_for(job.log, version: 'v2') response.should deliver_json_for(job.log, version: 'v2')
end end
end end
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' }
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
end
end end
describe 'PATCH /jobs/:job_id/log' do describe 'PATCH /jobs/:job_id/log' do