Commit c0d1383c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'eb-no-keep-report-artifacts' into 'master'

Don't show keep path for non archive artifacts

See merge request gitlab-org/gitlab!21553
parents d8348cac a792ea39
...@@ -717,8 +717,8 @@ module Ci ...@@ -717,8 +717,8 @@ module Ci
end end
end end
def has_expiring_artifacts? def has_expiring_archive_artifacts?
artifacts_expire_at.present? && artifacts_expire_at > Time.now has_expiring_artifacts? && artifacts_file&.exists?
end end
def keep_artifacts! def keep_artifacts!
...@@ -933,6 +933,10 @@ module Ci ...@@ -933,6 +933,10 @@ module Ci
value.with_indifferent_access value.with_indifferent_access
end end
end end
def has_expiring_artifacts?
artifacts_expire_at.present? && artifacts_expire_at > Time.now
end
end end
end end
......
...@@ -14,7 +14,7 @@ class BuildArtifactEntity < Grape::Entity ...@@ -14,7 +14,7 @@ class BuildArtifactEntity < Grape::Entity
download_project_job_artifacts_path(project, job) download_project_job_artifacts_path(project, job)
end end
expose :keep_path, if: -> (*) { job.has_expiring_artifacts? } do |job| expose :keep_path, if: -> (*) { job.has_expiring_archive_artifacts? } do |job|
keep_project_job_artifacts_path(project, job) keep_project_job_artifacts_path(project, job)
end end
......
...@@ -31,7 +31,7 @@ class BuildDetailsEntity < JobEntity ...@@ -31,7 +31,7 @@ class BuildDetailsEntity < JobEntity
browse_project_job_artifacts_path(project, build) browse_project_job_artifacts_path(project, build)
end end
expose :keep_path, if: -> (*) { build.has_expiring_artifacts? && can?(current_user, :update_build, build) } do |build| expose :keep_path, if: -> (*) { build.has_expiring_archive_artifacts? && can?(current_user, :update_build, build) } do |build|
keep_project_job_artifacts_path(project, build) keep_project_job_artifacts_path(project, build)
end end
......
---
title: Remove keep button for non archive artifacts
merge_request: 21553
author:
type: fixed
...@@ -2245,14 +2245,24 @@ describe Ci::Build do ...@@ -2245,14 +2245,24 @@ describe Ci::Build do
end end
end end
describe '#has_expiring_artifacts?' do describe '#has_expiring_archive_artifacts?' do
context 'when artifacts have expiration date set' do context 'when artifacts have expiration date set' do
before do before do
build.update(artifacts_expire_at: 1.day.from_now) build.update(artifacts_expire_at: 1.day.from_now)
end end
context 'and job artifacts file exists' do
let!(:archive) { create(:ci_job_artifact, :archive, job: build) }
it 'has expiring artifacts' do it 'has expiring artifacts' do
expect(build).to have_expiring_artifacts expect(build).to have_expiring_archive_artifacts
end
end
context 'and job artifacts file does not exist' do
it 'does not have expiring artifacts' do
expect(build).not_to have_expiring_archive_artifacts
end
end end
end end
...@@ -2262,7 +2272,7 @@ describe Ci::Build do ...@@ -2262,7 +2272,7 @@ describe Ci::Build do
end end
it 'does not have expiring artifacts' do it 'does not have expiring artifacts' do
expect(build).not_to have_expiring_artifacts expect(build).not_to have_expiring_archive_artifacts
end end
end end
end end
......
...@@ -4,6 +4,8 @@ require 'spec_helper' ...@@ -4,6 +4,8 @@ require 'spec_helper'
describe BuildArtifactEntity do describe BuildArtifactEntity do
let(:job) { create(:ci_build, name: 'test:job', artifacts_expire_at: 1.hour.from_now) } let(:job) { create(:ci_build, name: 'test:job', artifacts_expire_at: 1.hour.from_now) }
let!(:archive) { create(:ci_job_artifact, :archive, job: job) }
let!(:metadata) { create(:ci_job_artifact, :metadata, job: job) }
let(:entity) do let(:entity) do
described_class.new(job, request: double) described_class.new(job, request: double)
......
...@@ -176,5 +176,27 @@ describe BuildDetailsEntity do ...@@ -176,5 +176,27 @@ describe BuildDetailsEntity do
expect(subject[:reports].first[:file_type]).to eq('codequality') expect(subject[:reports].first[:file_type]).to eq('codequality')
end end
end end
context 'when the build has no archive type artifacts' do
let!(:report) { create(:ci_job_artifact, :codequality, job: build) }
it 'does not expose any artifact actions path' do
expect(subject[:artifact].keys).not_to include(:download_path, :browse_path, :keep_path)
end
end
context 'when the build has archive type artifacts' do
let!(:report) { create(:ci_job_artifact, :codequality, job: build) }
let!(:archive) { create(:ci_job_artifact, :archive, job: build) }
let!(:metadata) { create(:ci_job_artifact, :metadata, job: build) }
before do
build.update(artifacts_expire_at: 7.days.from_now)
end
it 'exposes artifact details' do
expect(subject[:artifact].keys).to include(:download_path, :browse_path, :keep_path, :expire_at, :expired)
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment