2016-11-03 11:54:10 +00:00
|
|
|
class BuildEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :id
|
|
|
|
expose :name
|
|
|
|
|
2016-11-17 15:08:05 +00:00
|
|
|
expose :build_path do |build|
|
2017-05-16 11:41:15 +00:00
|
|
|
path_to(:namespace_project_job, build)
|
2016-11-03 11:54:10 +00:00
|
|
|
end
|
|
|
|
|
2017-06-02 18:32:37 +00:00
|
|
|
expose :retry_path, if: -> (*) { build&.retryable? } do |build|
|
|
|
|
path_to(:retry_namespace_project_job, build)
|
2016-11-03 12:35:57 +00:00
|
|
|
end
|
|
|
|
|
2017-05-03 10:32:39 +00:00
|
|
|
expose :play_path, if: -> (*) { playable? } do |build|
|
2017-05-16 11:41:15 +00:00
|
|
|
path_to(:play_namespace_project_job, build)
|
2016-11-03 12:35:57 +00:00
|
|
|
end
|
|
|
|
|
2017-03-17 16:25:17 +00:00
|
|
|
expose :playable?, as: :playable
|
2016-11-29 10:57:16 +00:00
|
|
|
expose :created_at
|
|
|
|
expose :updated_at
|
2017-03-10 15:16:48 +00:00
|
|
|
expose :detailed_status, as: :status, with: StatusEntity
|
2016-11-29 10:57:16 +00:00
|
|
|
|
2016-11-03 12:35:57 +00:00
|
|
|
private
|
|
|
|
|
2017-03-03 06:59:25 +00:00
|
|
|
alias_method :build, :object
|
|
|
|
|
2017-04-06 10:58:13 +00:00
|
|
|
def playable?
|
2017-05-09 04:15:34 +00:00
|
|
|
build.playable? && can?(request.current_user, :update_build, build)
|
2016-11-03 11:54:10 +00:00
|
|
|
end
|
2017-03-03 06:59:25 +00:00
|
|
|
|
|
|
|
def detailed_status
|
2017-05-09 04:15:34 +00:00
|
|
|
build.detailed_status(request.current_user)
|
2017-03-03 06:59:25 +00:00
|
|
|
end
|
2017-04-06 10:58:13 +00:00
|
|
|
|
|
|
|
def path_to(route, build)
|
|
|
|
send("#{route}_path", build.project.namespace, build.project, build)
|
|
|
|
end
|
2016-11-03 11:54:10 +00:00
|
|
|
end
|