gitlab-org--gitlab-foss/app/serializers/pipeline_entity.rb

84 lines
2.1 KiB
Ruby
Raw Normal View History

class PipelineEntity < Grape::Entity
include RequestAwareEntity
expose :id
expose :user, using: UserEntity
2017-05-09 00:15:34 -04:00
expose :active?, as: :active
expose :coverage
2016-11-10 15:16:54 -05:00
expose :path do |pipeline|
2016-11-10 12:15:16 -05:00
namespace_project_pipeline_path(
pipeline.project.namespace,
pipeline.project,
pipeline)
end
expose :details do
expose :detailed_status, as: :status, with: StatusEntity
2016-11-10 11:50:55 -05:00
expose :duration
expose :finished_at
expose :stages, using: StageEntity
expose :artifacts, using: BuildArtifactEntity
expose :manual_actions, using: BuildActionEntity
2016-11-10 11:50:55 -05:00
end
expose :flags do
expose :latest?, as: :latest
expose :triggered?, as: :triggered
2016-12-15 16:06:39 -05:00
expose :stuck?, as: :stuck
expose :has_yaml_errors?, as: :yaml_errors
expose :can_retry?, as: :retryable
expose :can_cancel?, as: :cancelable
end
expose :ref do
expose :name do |pipeline|
pipeline.ref
end
expose :path do |pipeline|
if pipeline.ref
project_ref_path(pipeline.project, pipeline.ref)
end
end
expose :tag?, as: :tag
expose :branch?, as: :branch
end
expose :commit, using: CommitEntity
expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? }
expose :retry_path, if: -> (*) { can_retry? } do |pipeline|
retry_namespace_project_pipeline_path(pipeline.project.namespace,
pipeline.project,
pipeline.id)
end
expose :cancel_path, if: -> (*) { can_cancel? } do |pipeline|
cancel_namespace_project_pipeline_path(pipeline.project.namespace,
pipeline.project,
pipeline.id)
2016-11-10 15:16:54 -05:00
end
expose :created_at, :updated_at
private
alias_method :pipeline, :object
def can_retry?
2017-05-09 00:15:34 -04:00
can?(request.current_user, :update_pipeline, pipeline) &&
2017-04-06 08:31:38 -04:00
pipeline.retryable?
end
def can_cancel?
2017-05-09 00:15:34 -04:00
can?(request.current_user, :update_pipeline, pipeline) &&
2017-04-06 08:31:38 -04:00
pipeline.cancelable?
end
def detailed_status
2017-05-09 00:15:34 -04:00
pipeline.detailed_status(request.current_user)
end
end