From 31371686c95878ff06eb53728de011d5dc281c3c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 28 Jan 2013 03:04:36 +0100 Subject: [PATCH] Redirect to archive logs --- Gemfile.lock | 2 +- lib/travis/api/app/endpoint/jobs.rb | 15 ++++++++++++++- spec/integration/v2/jobs_spec.rb | 26 ++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 98ba2bd9..b82358b1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: be085ccf0aa58fba8d383d6ed72d22e47dae5836 + revision: 2d766c54c2fea70dfc4d937c22413eee937f002b specs: travis-core (0.0.1) actionmailer (~> 3.2.11) diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 963e2c59..288c6bb9 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -12,7 +12,20 @@ class Travis::Api::App end get '/:job_id/log' do - respond_with service(:find_artifact, params) + resource = service(:find_artifact, params).run + if !resource || resource.archived? + redirect archive_url("/jobs/#{params[:job_id]}/log.txt") + else + respond_with resource + end + end + + def archive_url(path) + "https://#{hostname('archive')}#{path}" + end + + def hostname(name) + "#{name}#{'-staging' if Travis.env == 'staging'}.#{Travis.config.host.split('.')[-2, 2].join('.')}" end end end diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index 58e370ef..847e56f5 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -18,9 +18,27 @@ describe 'Jobs' do response.should deliver_json_for(job, version: 'v2') end - it '/jobs/:id' do - job.log.update_attributes!(content: 'the log') - response = get "/jobs/#{job.id}/log.txt", {}, headers - response.should deliver_as_txt('the log', version: 'v2') + context 'GET /jobs/:job_id/log.txt' do + it 'returns log for a job' do + job.log.update_attributes!(content: 'the log') + response = get "/jobs/#{job.id}/log.txt", {}, headers + response.should deliver_as_txt('the log', version: 'v2') + end + + context 'when log is archived' do + it 'redirects to archive' do + job.log.update_attributes!(content: 'the log', archived_at: Time.now, archive_verified: true) + response = get "/jobs/#{job.id}/log.txt", {}, headers + response.should redirect_to("https://archive.travis-ci.org/jobs/#{job.id}/log.txt") + end + end + + context 'when log is missing' do + it 'redirects to archive' do + job.log.destroy + response = get "/jobs/#{job.id}/log.txt", {}, headers + response.should redirect_to("https://archive.travis-ci.org/jobs/#{job.id}/log.txt") + end + end end end