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

93 lines
2.3 KiB
Ruby
Raw Normal View History

class PipelineEntity < Grape::Entity
include RequestAwareEntity
expose :id
2016-11-10 20:16:54 +00:00
expose :user, if: proc { created_exposure? }, using: UserEntity
2016-11-10 17:15:16 +00:00
expose :url do |pipeline|
namespace_project_pipeline_path(
pipeline.project.namespace,
pipeline.project,
pipeline)
end
2016-11-10 20:16:54 +00:00
expose :details, if: proc { updated_exposure? } do
2016-11-10 16:50:55 +00:00
expose :status
expose :duration
expose :finished_at
expose :stages_with_statuses, as: :stages, using: PipelineStageEntity
expose :artifacts, using: PipelineArtifactEntity
expose :manual_actions, using: PipelineActionEntity
end
2016-11-10 20:16:54 +00:00
expose :flags, if: proc { created_exposure? } do
expose :latest?, as: :latest
expose :triggered?, as: :triggered
2016-11-10 20:16:54 +00:00
expose :yaml_errors?, as: :yaml_errors do |pipeline|
pipeline.yaml_errors.present?
end
2016-11-10 20:16:54 +00:00
expose :stuck?, as: :stuck do |pipeline|
pipeline.builds.any?(&:stuck?)
end
end
2016-11-10 20:16:54 +00:00
expose :ref, if: proc { updated_exposure? } do
expose :name do |pipeline|
pipeline.ref
end
2016-11-10 17:15:16 +00:00
expose :url do |pipeline|
namespace_project_tree_url(
pipeline.project.namespace,
pipeline.project,
id: pipeline.ref)
end
expose :tag?
end
2016-11-10 20:16:54 +00:00
expose :commit, if: proc { created_exposure? }, using: CommitEntity
2016-11-10 20:16:54 +00:00
expose :retry_url, if: proc { updated_exposure? } do |pipeline|
can?(request.user, :update_pipeline, pipeline.project) &&
pipeline.retryable? &&
2016-11-10 20:16:54 +00:00
retry_namespace_project_pipeline_path(pipeline.project.namespace,
pipeline.project, pipeline.id)
end
2016-11-10 20:16:54 +00:00
expose :cancel_url, if: proc { updated_exposure? } do |pipeline|
can?(request.user, :update_pipeline, pipeline.project) &&
pipeline.cancelable? &&
2016-11-10 20:16:54 +00:00
cancel_namespace_project_pipeline_path(pipeline.project.namespace,
pipeline.project, pipeline.id)
end
expose :created_at, :updated_at
2016-11-10 20:16:54 +00:00
def created_exposure?
!incremental? || created?
end
def updated_exposure?
!incremental? || updated?
end
2016-11-10 20:16:54 +00:00
def incremental?
options[:incremental] && last_updated
2016-11-10 20:16:54 +00:00
end
2016-11-10 20:16:54 +00:00
def last_updated
options.fetch(:last_updated)
end
2016-11-10 20:16:54 +00:00
def updated?
@object.updated_at > last_updated
end
2016-11-10 20:16:54 +00:00
def created?
@object.created_at > last_updated
end
end