2017-08-17 22:00:37 +05:30
|
|
|
class PipelineEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :id
|
|
|
|
expose :user, using: UserEntity
|
|
|
|
expose :active?, as: :active
|
|
|
|
expose :coverage
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :source
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :created_at, :updated_at
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :path do |pipeline|
|
|
|
|
project_pipeline_path(pipeline.project, pipeline)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :flags do
|
|
|
|
expose :latest?, as: :latest
|
|
|
|
expose :stuck?, as: :stuck
|
2018-03-17 18:26:18 +05:30
|
|
|
expose :auto_devops_source?, as: :auto_devops
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :has_yaml_errors?, as: :yaml_errors
|
|
|
|
expose :can_retry?, as: :retryable
|
|
|
|
expose :can_cancel?, as: :cancelable
|
2018-03-17 18:26:18 +05:30
|
|
|
expose :failure_reason?, as: :failure_reason
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :details do
|
|
|
|
expose :detailed_status, as: :status, with: StatusEntity
|
|
|
|
expose :duration
|
|
|
|
expose :finished_at
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :ref do
|
|
|
|
expose :name do |pipeline|
|
|
|
|
pipeline.ref
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :path do |pipeline|
|
|
|
|
if pipeline.ref
|
2017-09-10 17:25:29 +05:30
|
|
|
project_ref_path(pipeline.project, pipeline.ref)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :tag?, as: :tag
|
|
|
|
expose :branch?, as: :branch
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :commit, using: CommitEntity
|
2018-03-17 18:26:18 +05:30
|
|
|
expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? }
|
|
|
|
|
|
|
|
expose :failure_reason, if: -> (pipeline, _) { pipeline.failure_reason? } do |pipeline|
|
|
|
|
pipeline.present.failure_reason
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expose :retry_path, if: -> (*) { can_retry? } do |pipeline|
|
2017-09-10 17:25:29 +05:30
|
|
|
retry_project_pipeline_path(pipeline.project, pipeline)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :cancel_path, if: -> (*) { can_cancel? } do |pipeline|
|
2017-09-10 17:25:29 +05:30
|
|
|
cancel_project_pipeline_path(pipeline.project, pipeline)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
alias_method :pipeline, :object
|
|
|
|
|
|
|
|
def can_retry?
|
|
|
|
can?(request.current_user, :update_pipeline, pipeline) &&
|
|
|
|
pipeline.retryable?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_cancel?
|
|
|
|
can?(request.current_user, :update_pipeline, pipeline) &&
|
|
|
|
pipeline.cancelable?
|
|
|
|
end
|
|
|
|
|
|
|
|
def detailed_status
|
|
|
|
pipeline.detailed_status(request.current_user)
|
|
|
|
end
|
|
|
|
end
|