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
end
end
def has_expiring_artifacts?
artifacts_expire_at.present? && artifacts_expire_at > Time.now
def has_expiring_archive_artifacts?
has_expiring_artifacts? && artifacts_file&.exists?
end
def keep_artifacts!
......@@ -933,6 +933,10 @@ module Ci
value.with_indifferent_access
end
end
def has_expiring_artifacts?
artifacts_expire_at.present? && artifacts_expire_at > Time.now
end
end
end
......
......@@ -14,7 +14,7 @@ class BuildArtifactEntity < Grape::Entity
download_project_job_artifacts_path(project, job)
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)
end
......
......@@ -31,7 +31,7 @@ class BuildDetailsEntity < JobEntity
browse_project_job_artifacts_path(project, build)
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)
end
......
---
title: Remove keep button for non archive artifacts
merge_request: 21553
author:
type: fixed
......@@ -2245,14 +2245,24 @@ describe Ci::Build do
end
end
describe '#has_expiring_artifacts?' do
describe '#has_expiring_archive_artifacts?' do
context 'when artifacts have expiration date set' do
before do
build.update(artifacts_expire_at: 1.day.from_now)
end
it 'has expiring artifacts' do
expect(build).to have_expiring_artifacts
context 'and job artifacts file exists' do
let!(:archive) { create(:ci_job_artifact, :archive, job: build) }
it 'has expiring artifacts' do
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
......@@ -2262,7 +2272,7 @@ describe Ci::Build do
end
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
......
......@@ -4,6 +4,8 @@ require 'spec_helper'
describe BuildArtifactEntity do
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
described_class.new(job, request: double)
......
......@@ -176,5 +176,27 @@ describe BuildDetailsEntity do
expect(subject[:reports].first[:file_type]).to eq('codequality')
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
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