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

114 lines
3.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-06-07 05:36:41 -04:00
class BuildDetailsEntity < JobEntity
expose :coverage, :erased_at, :duration
expose :tag_list, as: :tags
expose :has_trace?, as: :has_trace
2018-10-12 13:13:41 -04:00
expose :stage
2018-10-25 07:53:00 -04:00
expose :stuck?, as: :stuck
expose :user, using: UserEntity
expose :runner, using: RunnerEntity
expose :pipeline, using: PipelineEntity
expose :deployment_status, if: -> (*) { build.starts_environment? } do
expose :deployment_status, as: :status
expose :persisted_environment, as: :environment, with: EnvironmentEntity
end
2018-03-22 12:52:28 -04:00
expose :metadata, using: BuildMetadataEntity
2018-02-20 22:03:12 -05:00
expose :artifact, if: -> (*) { can?(current_user, :read_build, build) } do
expose :download_path, if: -> (*) { build.artifacts? } do |build|
download_project_job_artifacts_path(project, build)
end
expose :browse_path, if: -> (*) { build.browsable_artifacts? } do |build|
browse_project_job_artifacts_path(project, build)
end
expose :keep_path, if: -> (*) { build.has_expiring_artifacts? && can?(current_user, :update_build, build) } do |build|
keep_project_job_artifacts_path(project, build)
end
expose :expire_at, if: -> (*) { build.artifacts_expire_at.present? } do |build|
build.artifacts_expire_at
end
expose :expired, if: -> (*) { build.artifacts_expire_at.present? } do |build|
build.artifacts_expired?
end
end
2017-05-29 03:58:20 -04:00
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
2017-11-06 08:20:44 -05:00
expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :erase_build, build) } do |build|
erase_project_job_path(project, build)
2017-05-29 03:58:20 -04:00
end
expose :terminal_path, if: -> (*) { can_create_build_terminal? } do |build|
terminal_project_job_path(project, build)
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
expose :trigger, if: -> (*) { build.trigger_request } do
expose :trigger_short_token, as: :short_token
expose :trigger_variables, as: :variables, using: TriggerVariableEntity
end
expose :runners do
expose :online do |build|
build.any_runners_online?
end
expose :available do |build|
project.any_runners?
end
expose :settings_path, if: -> (*) { can_admin_build? } do |build|
project_runners_path(project)
end
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_url(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
def can_create_build_terminal?
can?(current_user, :create_build_terminal, build) && build.has_terminal?
end
def can_admin_build?
can?(request.current_user, :admin_build, project)
end
end