Commit 23366edf authored by Robert Speicher's avatar Robert Speicher

Merge branch '6649-extract-ee-specific-files-lines-for-ci-cd-app-serializers' into 'master'

Resolve "Extract EE specific files/lines for CI/CD app/serializers"

Closes #6649

See merge request gitlab-org/gitlab-ee!10670
parents 35c9ecf5 97cd321e
......@@ -7,7 +7,6 @@ class PipelineDetailsEntity < PipelineEntity
expose :manual_actions, using: BuildActionEntity
expose :scheduled_actions, using: BuildActionEntity
end
expose :triggered_by_pipeline, as: :triggered_by, with: TriggeredPipelineEntity
expose :triggered_pipelines, as: :triggered, using: TriggeredPipelineEntity
end
PipelineDetailsEntity.prepend(EE::PipelineDetailsEntity)
......@@ -7,25 +7,7 @@ class PipelineSerializer < BaseSerializer
# rubocop: disable CodeReuse/ActiveRecord
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
resource = resource.preload([
:stages,
:retryable_builds,
:cancelable_statuses,
:trigger_requests,
{ triggered_by_pipeline: [:project, :user] },
{ triggered_pipelines: [:project, :user] },
:manual_actions,
:scheduled_actions,
:artifacts,
:merge_request,
{
pending_builds: :project,
project: [:route, { namespace: :route }],
artifacts: {
project: [:route, { namespace: :route }]
}
}
])
resource = resource.preload(preloaded_relations)
end
if paginated?
......@@ -53,4 +35,28 @@ class PipelineSerializer < BaseSerializer
data = represent(resource, { only: [{ details: [:stages] }], preload: true })
data.dig(:details, :stages) || []
end
private
def preloaded_relations
[
:stages,
:retryable_builds,
:cancelable_statuses,
:trigger_requests,
:manual_actions,
:scheduled_actions,
:artifacts,
:merge_request,
{
pending_builds: :project,
project: [:route, { namespace: :route }],
artifacts: {
project: [:route, { namespace: :route }]
}
}
]
end
end
PipelineSerializer.prepend(EE::PipelineSerializer)
# frozen_string_literal: true
module EE
module PipelineDetailsEntity
extend ActiveSupport::Concern
prepended do
expose :triggered_by_pipeline, as: :triggered_by, with: TriggeredPipelineEntity
expose :triggered_pipelines, as: :triggered, using: TriggeredPipelineEntity
end
end
end
# frozen_string_literal: true
module EE
module PipelineSerializer
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
private
override :preloaded_relations
def preloaded_relations
super.concat([
{ triggered_by_pipeline: [:project, :user] },
{ triggered_pipelines: [:project, :user] }
])
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