debian-mirror-gitlab/app/serializers/merge_requests/pipeline_entity.rb
2023-03-17 16:20:25 +05:30

61 lines
1.7 KiB
Ruby

# frozen_string_literal: true
class MergeRequests::PipelineEntity < Grape::Entity
include RequestAwareEntity
expose :id
expose :active?, as: :active
expose :name
expose :path do |pipeline|
project_pipeline_path(pipeline.project, pipeline)
end
expose :flags do
expose :merged_result_pipeline?, as: :merge_request_pipeline
end
expose :commit, using: CommitEntity
expose :details do
expose :event_type_name do |pipeline|
pipeline.present.event_type_name
end
expose :name do |pipeline| # To be removed in 15.7
pipeline.present.event_type_name
end
expose :artifacts do |pipeline, options|
rel = pipeline.downloadable_artifacts
if Feature.enabled?(:non_public_artifacts, type: :development)
rel = rel.select { |artifact| can?(request.current_user, :read_job_artifacts, artifact) }
end
BuildArtifactEntity.represent(rel, options.merge(project: pipeline.project))
end
expose :detailed_status, as: :status, with: DetailedStatusEntity do |pipeline|
pipeline.detailed_status(request.current_user)
end
expose :stages, using: StageEntity
expose :finished_at
end
# Coverage isn't always necessary (e.g. when displaying project pipelines in
# the UI). Instead of creating an entirely different entity we just allow the
# disabling of this specific field whenever necessary.
expose :coverage, unless: proc { options[:disable_coverage] } do |pipeline|
pipeline.present.coverage
end
expose :ref do
expose :branch?, as: :branch
end
expose :triggered_by_pipeline, as: :triggered_by, with: TriggeredPipelineEntity
expose :triggered_pipelines, as: :triggered, using: TriggeredPipelineEntity
end