Commit 0286eafe authored by Filipa Lacerda's avatar Filipa Lacerda Committed by Kamil Trzciński

Adds expanded triggered pipeline in the API

parent 1486304d
......@@ -69,7 +69,7 @@ class Projects::PipelinesController < Projects::ApplicationController
render json: PipelineSerializer
.new(project: @project, current_user: @current_user)
.represent(@pipeline, grouped: true)
.represent(@pipeline, grouped: true, expanded: params[:expanded].to_a)
end
end
end
......
......@@ -15,8 +15,12 @@ class TriggeredPipelineEntity < Grape::Entity
expose :details do
expose :detailed_status, as: :status, with: DetailedStatusEntity
expose :ordered_stages, as: :stages, using: StageEntity, if: -> (_, opts) { expand?(opts) }
end
expose :triggered_by_pipeline, as: :triggered_by, with: TriggeredPipelineEntity, if: -> (_, opts) { expand_for_path?(opts, :triggered_by) }
expose :triggered_pipelines, as: :triggered, using: TriggeredPipelineEntity, if: -> (_, opts) { expand_for_path?(opts, :triggered) }
expose :project, using: ProjectEntity
private
......@@ -26,4 +30,12 @@ class TriggeredPipelineEntity < Grape::Entity
def detailed_status
pipeline.detailed_status(request.current_user)
end
def expand?(opts)
opts[:expanded].to_a.include?(pipeline.id)
end
def expand_for_path?(opts, path)
opts[:attr_path].last == path && expand?(opts)
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