2016-11-10 09:32:23 -05:00
|
|
|
class PipelineEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :id
|
2016-12-01 05:59:00 -05:00
|
|
|
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
|
|
|
|
2016-12-15 09:57:35 -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
|
2016-11-10 09:32:23 -05:00
|
|
|
|
2016-12-01 05:59:00 -05:00
|
|
|
expose :details do
|
2017-03-10 07:56:35 -05:00
|
|
|
expose :detailed_status, as: :status, with: StatusEntity
|
2016-11-10 11:50:55 -05:00
|
|
|
expose :duration
|
|
|
|
expose :finished_at
|
2016-12-21 08:51:53 -05:00
|
|
|
expose :stages, using: StageEntity
|
|
|
|
expose :artifacts, using: BuildArtifactEntity
|
|
|
|
expose :manual_actions, using: BuildActionEntity
|
2016-11-10 11:50:55 -05:00
|
|
|
end
|
2016-11-10 09:32:23 -05:00
|
|
|
|
2016-12-01 05:59:00 -05:00
|
|
|
expose :flags do
|
2016-11-10 09:32:23 -05:00
|
|
|
expose :latest?, as: :latest
|
|
|
|
expose :triggered?, as: :triggered
|
2016-12-15 16:06:39 -05:00
|
|
|
expose :stuck?, as: :stuck
|
2016-12-21 08:26:47 -05:00
|
|
|
expose :has_yaml_errors?, as: :yaml_errors
|
|
|
|
expose :can_retry?, as: :retryable
|
|
|
|
expose :can_cancel?, as: :cancelable
|
2016-11-10 09:32:23 -05:00
|
|
|
end
|
|
|
|
|
2016-12-01 05:59:00 -05:00
|
|
|
expose :ref do
|
2016-11-10 09:32:23 -05:00
|
|
|
expose :name do |pipeline|
|
|
|
|
pipeline.ref
|
|
|
|
end
|
|
|
|
|
2016-12-21 08:26:47 -05:00
|
|
|
expose :path do |pipeline|
|
2017-01-20 06:44:31 -05:00
|
|
|
if pipeline.ref
|
2017-05-11 11:47:44 -04:00
|
|
|
project_ref_path(pipeline.project, pipeline.ref)
|
2017-01-20 06:44:31 -05:00
|
|
|
end
|
2016-11-10 09:32:23 -05:00
|
|
|
end
|
|
|
|
|
2016-12-21 08:26:47 -05:00
|
|
|
expose :tag?, as: :tag
|
|
|
|
expose :branch?, as: :branch
|
2016-11-10 09:32:23 -05:00
|
|
|
end
|
|
|
|
|
2016-12-01 05:59:00 -05:00
|
|
|
expose :commit, using: CommitEntity
|
2017-05-03 06:32:39 -04:00
|
|
|
expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? }
|
2016-11-10 09:32:23 -05:00
|
|
|
|
2017-05-03 06:32:39 -04:00
|
|
|
expose :retry_path, if: -> (*) { can_retry? } do |pipeline|
|
2016-12-21 08:26:47 -05:00
|
|
|
retry_namespace_project_pipeline_path(pipeline.project.namespace,
|
|
|
|
pipeline.project,
|
|
|
|
pipeline.id)
|
2016-11-10 09:32:23 -05:00
|
|
|
end
|
|
|
|
|
2017-05-03 06:32:39 -04:00
|
|
|
expose :cancel_path, if: -> (*) { can_cancel? } do |pipeline|
|
2016-12-21 08:26:47 -05:00
|
|
|
cancel_namespace_project_pipeline_path(pipeline.project.namespace,
|
|
|
|
pipeline.project,
|
|
|
|
pipeline.id)
|
2016-11-10 15:16:54 -05:00
|
|
|
end
|
|
|
|
|
2016-11-12 04:05:57 -05:00
|
|
|
expose :created_at, :updated_at
|
2016-12-21 08:26:47 -05:00
|
|
|
|
|
|
|
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?
|
2016-12-21 08:26:47 -05:00
|
|
|
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?
|
2016-12-21 08:26:47 -05:00
|
|
|
end
|
2017-03-03 01:59:25 -05:00
|
|
|
|
|
|
|
def detailed_status
|
2017-05-09 00:15:34 -04:00
|
|
|
pipeline.detailed_status(request.current_user)
|
2017-03-03 01:59:25 -05:00
|
|
|
end
|
2016-11-10 09:32:23 -05:00
|
|
|
end
|