Commit 31bd09a3 authored by Matija Čupić's avatar Matija Čupić

Expose report download path in build details

Exposes report download paths in build details.
parent 51183ad3
......@@ -42,6 +42,10 @@ class BuildDetailsEntity < JobEntity
end
end
expose :reports, if: -> (*) { can?(current_user, :read_build, build) }, using: JobArtifactEntity do |build|
build.job_artifacts.merge(Ci::JobArtifact.with_all_reports)
end
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :erase_build, build) } do |build|
erase_project_job_path(project, build)
......
# frozen_string_literal: true
class JobArtifactEntity < Grape::Entity
include RequestAwareEntity
expose :file_type
expose :file_format
expose :size
expose :download_path do |artifact|
download_project_job_artifacts_path(job.project, job, file_type: artifact.file_format)
end
alias_method :job, :object
end
......@@ -146,5 +146,13 @@ describe BuildDetailsEntity do
end
end
end
context 'when the build has reports' do
let!(:report) { create(:ci_job_artifact, :codequality, job: build) }
it 'exposes the report artifacts' do
expect(subject[:reports]).not_to be_empty
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe JobArtifactEntity do
let(:report) { create(:ci_job_artifact, :codequality) }
let(:entity) { described_class.new(report, request: double) }
describe '#as_json' do
subject { entity.as_json }
it 'exposes file_type' do
expect(subject[:file_type]).to eq(report.file_type)
end
it 'exposes file_format' do
expect(subject[:file_format]).to eq(report.file_format)
end
it 'exposes size' do
expect(subject[:size]).to eq(report.size)
end
it 'exposes download path' do
expect(subject[:download_path]).to include("jobs/#{report.job.id}/artifacts/download")
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