diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 327114e0350..1506e957b3c 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -339,6 +339,12 @@ module Ci artifacts? end + def artifacts_browser_supported? + # TODO, since carrierwave 0.10.0 we will be able to check mime type here + # + artifacts? && artifacts_file.path.end_with?('zip') + end + def artifacts_metadata(path) [] end diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml index c7fd047949e..7d32711e642 100644 --- a/app/views/projects/builds/show.html.haml +++ b/app/views/projects/builds/show.html.haml @@ -96,7 +96,8 @@ .panel-body .btn-group{ role: :group } = link_to "Download", @build.artifacts_download_url, class: 'btn btn-sm btn-primary' - = link_to "Browse", @build.artifacts_browse_url, class: 'btn btn-sm btn-primary' + - if @build.artifacts_browser_supported? + = link_to "Browse", @build.artifacts_browse_url, class: 'btn btn-sm btn-primary' .build-widget %h4.title diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 33e0eb7d5d7..108d7d5ff01 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -391,6 +391,29 @@ describe Ci::Build, models: true do end end + + describe :artifacts_browser_supported? do + subject { build.artifacts_browser_supported? } + before do + file = fixture_file_upload(archive_file, archive_type) + build.update_attributes(artifacts_file: file) + end + + context 'artifacts archive is not a zip file' do + let(:archive_file) { Rails.root + 'spec/fixtures/banana_sample.gif' } + let(:archive_type) { 'image/gif' } + + it { is_expected.to be_falsy } + end + + context 'artifacts archive is a zip file' do + let(:archive_file) { Rails.root + 'spec/fixtures/ci_build_artifacts.zip' } + let(:archive_type) { 'application/zip' } + + it { is_expected.to be_truthy } + end + end + describe :repo_url do let(:build) { FactoryGirl.create :ci_build } let(:project) { build.project }