diff options
Diffstat (limited to 'app/serializers/pipeline_entity.rb')
-rw-r--r-- | app/serializers/pipeline_entity.rb | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index ad8b4d43e8f..c4f000b0ca3 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -3,32 +3,30 @@ class PipelineEntity < Grape::Entity expose :id expose :user, using: UserEntity + expose :active?, as: :active + expose :coverage + expose :source - expose :path do |pipeline| - namespace_project_pipeline_path( - pipeline.project.namespace, - pipeline.project, - pipeline) - end + expose :created_at, :updated_at - expose :details do - expose :detailed_status, as: :status, with: StatusEntity - expose :duration - expose :finished_at - expose :stages, using: StageEntity - expose :artifacts, using: BuildArtifactEntity - expose :manual_actions, using: BuildActionEntity + expose :path do |pipeline| + project_pipeline_path(pipeline.project, pipeline) end expose :flags do expose :latest?, as: :latest - expose :triggered?, as: :triggered expose :stuck?, as: :stuck expose :has_yaml_errors?, as: :yaml_errors expose :can_retry?, as: :retryable expose :can_cancel?, as: :cancelable end + expose :details do + expose :detailed_status, as: :status, with: StatusEntity + expose :duration + expose :finished_at + end + expose :ref do expose :name do |pipeline| pipeline.ref @@ -36,10 +34,7 @@ class PipelineEntity < Grape::Entity expose :path do |pipeline| if pipeline.ref - namespace_project_tree_path( - pipeline.project.namespace, - pipeline.project, - id: pipeline.ref) + project_ref_path(pipeline.project, pipeline.ref) end end @@ -48,37 +43,32 @@ class PipelineEntity < Grape::Entity end expose :commit, using: CommitEntity - expose :yaml_errors, if: ->(pipeline, _) { pipeline.has_yaml_errors? } - expose :retry_path, if: proc { can_retry? } do |pipeline| - retry_namespace_project_pipeline_path(pipeline.project.namespace, - pipeline.project, - pipeline.id) + expose :retry_path, if: -> (*) { can_retry? } do |pipeline| + retry_project_pipeline_path(pipeline.project, pipeline) end - expose :cancel_path, if: proc { can_cancel? } do |pipeline| - cancel_namespace_project_pipeline_path(pipeline.project.namespace, - pipeline.project, - pipeline.id) + expose :cancel_path, if: -> (*) { can_cancel? } do |pipeline| + cancel_project_pipeline_path(pipeline.project, pipeline) end - expose :created_at, :updated_at + expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? } private alias_method :pipeline, :object def can_retry? - can?(request.user, :update_pipeline, pipeline) && + can?(request.current_user, :update_pipeline, pipeline) && pipeline.retryable? end def can_cancel? - can?(request.user, :update_pipeline, pipeline) && + can?(request.current_user, :update_pipeline, pipeline) && pipeline.cancelable? end def detailed_status - pipeline.detailed_status(request.user) + pipeline.detailed_status(request.current_user) end end |