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

47 lines
1.3 KiB
Ruby
Raw Normal View History

2017-06-07 05:36:41 -04:00
class BuildDetailsEntity < JobEntity
expose :coverage, :erased_at, :duration
expose :tag_list, as: :tags
expose :user, using: UserEntity
expose :runner, using: RunnerEntity
expose :pipeline, using: PipelineEntity
2017-05-29 03:58:20 -04:00
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :update_build, project) } do |build|
erase_project_job_path(project, build)
2017-05-29 03:58:20 -04:00
end
expose :merge_request, if: -> (*) { can?(current_user, :read_merge_request, build.merge_request) } do
2017-05-29 03:58:20 -04:00
expose :iid do |build|
build.merge_request.iid
end
expose :path do |build|
project_merge_request_path(build.merge_request.project,
build.merge_request)
2017-05-29 03:58:20 -04:00
end
end
2017-06-02 14:32:37 -04:00
expose :new_issue_path, if: -> (*) { can?(request.current_user, :create_issue, project) && build.failed? } do |build|
new_project_issue_path(project, issue: build_failed_issue_options)
end
expose :raw_path do |build|
raw_project_job_path(project, build)
end
private
2017-06-02 14:32:37 -04:00
def build_failed_issue_options
2017-08-24 12:32:23 -04:00
{ title: "Job Failed ##{build.id}",
description: "Job [##{build.id}](#{project_job_path(project, build)}) failed for #{build.sha}:\n" }
2017-06-02 14:32:37 -04:00
end
def current_user
request.current_user
end
def project
build.project
end
end