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

42 lines
917 B
Ruby
Raw Normal View History

class BuildEntity < Grape::Entity
include RequestAwareEntity
expose :id
expose :name
expose :build_path do |build|
path_to(:namespace_project_job, build)
end
expose :build_failed_options, if: -> (*) { build.retryable? } do
expose :retry_path do |build|
path_to(:retry_namespace_project_job, build)
end
end
expose :play_path, if: -> (*) { playable? } do |build|
path_to(:play_namespace_project_job, build)
end
expose :playable?, as: :playable
expose :created_at
expose :updated_at
2017-03-10 15:16:48 +00:00
expose :detailed_status, as: :status, with: StatusEntity
private
alias_method :build, :object
def playable?
2017-05-09 04:15:34 +00:00
build.playable? && can?(request.current_user, :update_build, build)
end
def detailed_status
2017-05-09 04:15:34 +00:00
build.detailed_status(request.current_user)
end
def path_to(route, build)
send("#{route}_path", build.project.namespace, build.project, build)
end
end