Commit 10f7adfa authored by Daniel Stone's avatar Daniel Stone Committed by Heinrich Lee Yu

Use CI source project for path to exposed job artifacts

When routing paths to exposed job artifacts, we were always using the
destination project. However, in a cross-project MR, the job exposing
the artifacts is run in the source project, not in the destination
project. Change the arguments to project_job_path() to always use the
job's project for constructing the URL path.

!23738 tried a more expansive fix but this wasn't doable thanks to
project_job_path() also being a hidden Rails-generated helper function
which did take both project and job as an argument.

Fixes: #37341
parent ebaaefc3
...@@ -35,7 +35,7 @@ module Ci ...@@ -35,7 +35,7 @@ module Ci
{ {
text: job.artifacts_expose_as, text: job.artifacts_expose_as,
url: path_for_entries(metadata_entries, job), url: path_for_entries(metadata_entries, job),
job_path: project_job_path(project, job), job_path: project_job_path(job.project, job),
job_name: job.name job_name: job.name
} }
end end
...@@ -59,9 +59,9 @@ module Ci ...@@ -59,9 +59,9 @@ module Ci
return if entries.empty? return if entries.empty?
if single_artifact?(entries) if single_artifact?(entries)
file_project_job_artifacts_path(project, job, entries.first.path) file_project_job_artifacts_path(job.project, job, entries.first.path)
else else
browse_project_job_artifacts_path(project, job) browse_project_job_artifacts_path(job.project, job)
end end
end end
......
...@@ -172,5 +172,47 @@ describe Ci::FindExposedArtifactsService do ...@@ -172,5 +172,47 @@ describe Ci::FindExposedArtifactsService do
]) ])
end end
end end
context 'cross-project MR' do
let!(:foreign_project) { create(:project) }
let!(:pipeline) { create(:ci_pipeline, project: foreign_project) }
let!(:job_show) do
create_job_with_artifacts({
artifacts: {
expose_as: 'file artifact',
paths: ['ci_artifacts.txt']
}
})
end
let!(:job_browse) do
create_job_with_artifacts({
artifacts: {
expose_as: 'directory artifact',
paths: ['tests_encoding/']
}
})
end
subject { described_class.new(project, user).for_pipeline(pipeline, limit: 2) }
it 'returns the correct path for cross-project MRs' do
expect(subject).to eq([
{
text: 'file artifact',
url: file_project_job_artifacts_path(foreign_project, job_show, 'ci_artifacts.txt'),
job_name: job_show.name,
job_path: project_job_path(foreign_project, job_show)
},
{
text: 'directory artifact',
url: browse_project_job_artifacts_path(foreign_project, job_browse),
job_name: job_browse.name,
job_path: project_job_path(foreign_project, job_browse)
}
])
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