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

Merge branch 'mo-downloadable-locked-artifacts' into 'master'

Expose locked artifacts for pipeline downloadable_artifact

See merge request gitlab-org/gitlab!60836
parents 45b844d9 fad63dfb
...@@ -70,7 +70,9 @@ module Ci ...@@ -70,7 +70,9 @@ module Ci
has_many :deployments, through: :builds has_many :deployments, through: :builds
has_many :environments, -> { distinct }, through: :deployments has_many :environments, -> { distinct }, through: :deployments
has_many :latest_builds, -> { latest.with_project_and_metadata }, foreign_key: :commit_id, inverse_of: :pipeline, class_name: 'Ci::Build' has_many :latest_builds, -> { latest.with_project_and_metadata }, foreign_key: :commit_id, inverse_of: :pipeline, class_name: 'Ci::Build'
has_many :downloadable_artifacts, -> { not_expired.downloadable.with_job }, through: :latest_builds, source: :job_artifacts has_many :downloadable_artifacts, -> do
not_expired.or(where_exists(::Ci::Pipeline.artifacts_locked.where('ci_pipelines.id = ci_builds.commit_id'))).downloadable.with_job
end, through: :latest_builds, source: :job_artifacts
has_many :messages, class_name: 'Ci::PipelineMessage', inverse_of: :pipeline has_many :messages, class_name: 'Ci::PipelineMessage', inverse_of: :pipeline
......
---
title: Fix downloadable artifacts for pipeline
merge_request: 60836
author:
type: fixed
...@@ -68,14 +68,23 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do ...@@ -68,14 +68,23 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end end
describe '#downloadable_artifacts' do describe '#downloadable_artifacts' do
let(:build) { create(:ci_build, pipeline: pipeline) } let_it_be(:build) { create(:ci_build, pipeline: pipeline) }
let_it_be(:downloadable_artifact) { create(:ci_job_artifact, :codequality, job: build) }
let_it_be(:expired_artifact) { create(:ci_job_artifact, :junit, :expired, job: build) }
let_it_be(:undownloadable_artifact) { create(:ci_job_artifact, :trace, job: build) }
it 'returns downloadable artifacts that have not expired' do context 'when artifacts are locked' do
downloadable_artifact = create(:ci_job_artifact, :codequality, job: build) it 'returns downloadable artifacts including locked artifacts' do
_expired_artifact = create(:ci_job_artifact, :junit, :expired, job: build) expect(pipeline.downloadable_artifacts).to contain_exactly(downloadable_artifact, expired_artifact)
_undownloadable_artifact = create(:ci_job_artifact, :trace, job: build) end
end
expect(pipeline.downloadable_artifacts).to contain_exactly(downloadable_artifact) context 'when artifacts are unlocked' do
it 'returns only downloadable artifacts not expired' do
expired_artifact.job.pipeline.unlocked!
expect(pipeline.reload.downloadable_artifacts).to contain_exactly(downloadable_artifact)
end
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