Commit f4870f0b authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'mc/feature/expose-artifacts-locked' into 'master'

Consider artifact locking when exposing artifact information

See merge request gitlab-org/gitlab!32787
parents aa777b17 5d0537bb
...@@ -777,6 +777,8 @@ module Ci ...@@ -777,6 +777,8 @@ module Ci
end end
def artifacts_expired? def artifacts_expired?
return false if artifacts_locked?
artifacts_expire_at && artifacts_expire_at < Time.current artifacts_expire_at && artifacts_expire_at < Time.current
end end
...@@ -958,6 +960,10 @@ module Ci ...@@ -958,6 +960,10 @@ module Ci
private private
def artifacts_locked?
job_artifacts_archive&.locked?
end
def dependencies def dependencies
strong_memoize(:dependencies) do strong_memoize(:dependencies) do
Ci::BuildDependencies.new(self) Ci::BuildDependencies.new(self)
...@@ -1027,6 +1033,8 @@ module Ci ...@@ -1027,6 +1033,8 @@ module Ci
end end
def has_expiring_artifacts? def has_expiring_artifacts?
return false if artifacts_locked?
artifacts_expire_at.present? && artifacts_expire_at > Time.current artifacts_expire_at.present? && artifacts_expire_at > Time.current
end end
......
...@@ -23,6 +23,10 @@ class BuildArtifactEntity < Grape::Entity ...@@ -23,6 +23,10 @@ class BuildArtifactEntity < Grape::Entity
fast_browse_project_job_artifacts_path(project, job) fast_browse_project_job_artifacts_path(project, job)
end end
expose :locked, if: -> (*) { job.job_artifacts_archive.present? } do |job|
job.job_artifacts_archive.locked?
end
private private
alias_method :job, :object alias_method :job, :object
......
...@@ -46,6 +46,10 @@ class BuildDetailsEntity < JobEntity ...@@ -46,6 +46,10 @@ class BuildDetailsEntity < JobEntity
expose :expired, if: -> (*) { build.artifacts_expire_at.present? } do |build| expose :expired, if: -> (*) { build.artifacts_expire_at.present? } do |build|
build.artifacts_expired? build.artifacts_expired?
end end
expose :locked, if: -> (*) { build.job_artifacts_archive.present? } do |build|
build.job_artifacts_archive.locked?
end
end end
expose :report_artifacts, expose :report_artifacts,
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
"browse_path": { "type": "string"}, "browse_path": { "type": "string"},
"keep_path": { "type": "string"}, "keep_path": { "type": "string"},
"expired": { "type": "boolean" }, "expired": { "type": "boolean" },
"expire_at": { "type": "string", "format": "date-time" } "expire_at": { "type": "string", "format": "date-time" },
"locked": { "type": "boolean" }
}, },
"additionalProperties": false "additionalProperties": false
} }
...@@ -590,22 +590,28 @@ describe Ci::Build do ...@@ -590,22 +590,28 @@ describe Ci::Build do
describe '#artifacts?' do describe '#artifacts?' do
subject { build.artifacts? } subject { build.artifacts? }
context 'when new artifacts are used' do context 'artifacts archive does not exist' do
context 'artifacts archive does not exist' do let(:build) { create(:ci_build) }
let(:build) { create(:ci_build) }
it { is_expected.to be_falsy } it { is_expected.to be_falsy }
end end
context 'artifacts archive exists' do context 'artifacts archive exists' do
let(:build) { create(:ci_build, :artifacts) } let(:build) { create(:ci_build, :artifacts) }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
context 'is expired' do
let(:build) { create(:ci_build, :artifacts, :expired) }
it { is_expected.to be_falsy }
context 'is expired' do context 'is locked' do
let(:build) { create(:ci_build, :artifacts, :expired) } before do
build.job_artifacts_archive.update(locked: true)
end
it { is_expected.to be_falsy } it { is_expected.to be_truthy }
end end
end end
end end
...@@ -630,6 +636,14 @@ describe Ci::Build do ...@@ -630,6 +636,14 @@ describe Ci::Build do
end end
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
context 'is locked' do
before do
create(:ci_job_artifact, :archive, job: build, locked: true)
end
it { is_expected.to be_falsey }
end
end end
context 'is not expired' do context 'is not expired' do
...@@ -2252,6 +2266,16 @@ describe Ci::Build do ...@@ -2252,6 +2266,16 @@ describe Ci::Build do
it 'has expiring artifacts' do it 'has expiring artifacts' do
expect(build).to have_expiring_archive_artifacts expect(build).to have_expiring_archive_artifacts
end end
context 'and job artifacts are locked' do
before do
archive.update(locked: true)
end
it 'does not have expiring artifacts' do
expect(build).not_to have_expiring_archive_artifacts
end
end
end end
context 'and job artifacts archive record does not exist' do context 'and job artifacts archive record does not exist' do
......
...@@ -30,5 +30,9 @@ describe BuildArtifactEntity do ...@@ -30,5 +30,9 @@ describe BuildArtifactEntity do
expect(subject[:browse_path]) expect(subject[:browse_path])
.to include "jobs/#{job.id}/artifacts/browse" .to include "jobs/#{job.id}/artifacts/browse"
end end
it 'exposes locked information about artifact' do
expect(subject).to include(:locked)
end
end end
end end
...@@ -190,7 +190,7 @@ describe BuildDetailsEntity do ...@@ -190,7 +190,7 @@ describe BuildDetailsEntity do
let!(:report) { create(:ci_job_artifact, :codequality, job: build) } let!(:report) { create(:ci_job_artifact, :codequality, job: build) }
it 'exposes artifact details' do it 'exposes artifact details' do
expect(subject[:artifact].keys).to include(:download_path, :browse_path, :keep_path, :expire_at, :expired) expect(subject[:artifact].keys).to include(:download_path, :browse_path, :keep_path, :expire_at, :expired, :locked)
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