From 43e20332cf8026a60d3d01d8baa451d5fc9cbfe6 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Jan 2015 13:05:31 +0100 Subject: [PATCH] Return removed_at and removed_by if the log was removed --- Gemfile.lock | 10 ++++++++-- lib/travis/api/app/endpoint/jobs.rb | 4 +++- lib/travis/api/app/responders/json.rb | 9 +++++++-- lib/travis/api/v2/http.rb | 1 + lib/travis/api/v2/http/removed_log.rb | 20 ++++++++++++++++++++ spec/integration/v2/jobs_spec.rb | 12 ++++++++++++ 6 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 lib/travis/api/v2/http/removed_log.rb diff --git a/Gemfile.lock b/Gemfile.lock index 72c9eb88..7a96c14a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,6 +34,13 @@ GIT rack-cache (1.2) rack (>= 0.4) +GIT + remote: git://github.com/travis-ci/s3.git + revision: 386361c1b0ede19cde0ddaf86e41a16308575f5d + specs: + s3 (0.3.21) + proxies (~> 0.2.0) + GIT remote: git://github.com/travis-ci/travis-core.git revision: 8fa9680a47ab457187ddf3a88461a756a6f4c2a6 @@ -270,8 +277,6 @@ GEM rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.99.2) - s3 (0.3.21) - proxies (~> 0.2.0) sass (3.4.6) sidekiq (2.5.0) celluloid (~> 0.12.0) @@ -358,6 +363,7 @@ DEPENDENCIES rb-fsevent (~> 0.9.1) rerun rspec (~> 2.13) + s3! sentry-raven! sinatra sinatra-contrib diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 9a70becf..f14a4d5c 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -58,7 +58,9 @@ class Travis::Api::App get '/:job_id/log' do 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 # automatically here, so we need to check it explicitly if accepts?('text/plain') diff --git a/lib/travis/api/app/responders/json.rb b/lib/travis/api/app/responders/json.rb index 3bc3bb8d..8d8b0314 100644 --- a/lib/travis/api/app/responders/json.rb +++ b/lib/travis/api/app/responders/json.rb @@ -23,13 +23,18 @@ class Travis::Api::App return true unless resource.is_a?(Log) chunked = accept_params[:chunked] - chunked ? !resource.aggregated_at : true + if resource.removed_at + true + else + chunked ? !resource.aggregated_at : true + end end def result if builder 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 else basic_type_resource diff --git a/lib/travis/api/v2/http.rb b/lib/travis/api/v2/http.rb index a733b364..2e5427aa 100644 --- a/lib/travis/api/v2/http.rb +++ b/lib/travis/api/v2/http.rb @@ -16,6 +16,7 @@ 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' diff --git a/lib/travis/api/v2/http/removed_log.rb b/lib/travis/api/v2/http/removed_log.rb new file mode 100644 index 00000000..11fa032a --- /dev/null +++ b/lib/travis/api/v2/http/removed_log.rb @@ -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 diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index 1183d619..55cc3ba6 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -103,6 +103,18 @@ describe 'Jobs' do response.should deliver_json_for(job.log, version: 'v2') 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 describe 'PATCH /jobs/:job_id/log' do