2016-11-10 14:32:23 +00:00
|
|
|
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 14:32:23 +00:00
|
|
|
|
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 14:32:23 +00:00
|
|
|
|
2016-11-10 20:16:54 +00:00
|
|
|
expose :flags, if: proc { created_exposure? } do
|
2016-11-10 14:32:23 +00:00
|
|
|
expose :latest?, as: :latest
|
|
|
|
expose :triggered?, as: :triggered
|
2016-11-10 20:16:54 +00:00
|
|
|
|
2016-11-10 14:32:23 +00:00
|
|
|
expose :yaml_errors?, as: :yaml_errors do |pipeline|
|
|
|
|
pipeline.yaml_errors.present?
|
|
|
|
end
|
2016-11-10 20:16:54 +00:00
|
|
|
|
2016-11-10 14:32:23 +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
|
2016-11-10 14:32:23 +00:00
|
|
|
expose :name do |pipeline|
|
|
|
|
pipeline.ref
|
|
|
|
end
|
|
|
|
|
2016-11-10 17:15:16 +00:00
|
|
|
expose :url do |pipeline|
|
2016-11-10 14:32:23 +00:00
|
|
|
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 14:32:23 +00:00
|
|
|
|
2016-11-10 20:16:54 +00:00
|
|
|
expose :retry_url, if: proc { updated_exposure? } do |pipeline|
|
|
|
|
can?(request.user, :update_pipeline, pipeline.project) &&
|
2016-11-10 14:32:23 +00:00
|
|
|
pipeline.retryable? &&
|
2016-11-10 20:16:54 +00:00
|
|
|
retry_namespace_project_pipeline_path(pipeline.project.namespace,
|
|
|
|
pipeline.project, pipeline.id)
|
2016-11-10 14:32:23 +00:00
|
|
|
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) &&
|
2016-11-10 14:32:23 +00:00
|
|
|
pipeline.cancelable? &&
|
2016-11-10 20:16:54 +00:00
|
|
|
cancel_namespace_project_pipeline_path(pipeline.project.namespace,
|
|
|
|
pipeline.project, pipeline.id)
|
|
|
|
end
|
|
|
|
|
2016-11-12 09:05:57 +00:00
|
|
|
expose :created_at, :updated_at
|
|
|
|
|
2016-11-10 20:16:54 +00:00
|
|
|
def created_exposure?
|
|
|
|
!incremental? || created?
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated_exposure?
|
|
|
|
!incremental? || updated?
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|
|
|
|
|
2016-11-10 20:16:54 +00:00
|
|
|
def incremental?
|
2016-11-10 20:57:15 +00:00
|
|
|
options[:incremental] && last_updated
|
2016-11-10 20:16:54 +00:00
|
|
|
end
|
2016-11-10 14:32:23 +00:00
|
|
|
|
2016-11-10 20:16:54 +00:00
|
|
|
def last_updated
|
|
|
|
options.fetch(:last_updated)
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|
|
|
|
|
2016-11-10 20:16:54 +00:00
|
|
|
def updated?
|
|
|
|
@object.updated_at > last_updated
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|
|
|
|
|
2016-11-10 20:16:54 +00:00
|
|
|
def created?
|
|
|
|
@object.created_at > last_updated
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|
|
|
|
end
|