2018-07-19 18:43:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-07 09:36:41 +00:00
|
|
|
class BuildDetailsEntity < JobEntity
|
2017-05-23 15:10:07 +00:00
|
|
|
expose :coverage, :erased_at, :duration
|
|
|
|
expose :tag_list, as: :tags
|
2018-09-27 07:04:51 +00:00
|
|
|
expose :has_trace?, as: :has_trace
|
2018-10-12 17:13:41 +00:00
|
|
|
expose :stage
|
2018-10-25 11:53:00 +00:00
|
|
|
expose :stuck?, as: :stuck
|
2017-06-01 19:34:44 +00:00
|
|
|
expose :user, using: UserEntity
|
2017-06-13 09:05:48 +00:00
|
|
|
expose :runner, using: RunnerEntity
|
2019-05-06 08:08:42 +00:00
|
|
|
expose :metadata, using: BuildMetadataEntity
|
2021-01-26 00:08:57 +00:00
|
|
|
expose :pipeline, using: Ci::PipelineEntity
|
2017-06-01 19:34:44 +00:00
|
|
|
|
2018-10-15 06:26:01 +00:00
|
|
|
expose :deployment_status, if: -> (*) { build.starts_environment? } do
|
2018-08-20 13:15:53 +00:00
|
|
|
expose :deployment_status, as: :status
|
2019-05-06 13:20:20 +00:00
|
|
|
expose :persisted_environment, as: :environment do |build, options|
|
2019-05-06 15:30:57 +00:00
|
|
|
options.merge(deployment_details: false).yield_self do |opts|
|
2019-05-06 13:20:20 +00:00
|
|
|
EnvironmentEntity.represent(build.persisted_environment, opts)
|
|
|
|
end
|
|
|
|
end
|
2018-08-20 13:15:53 +00:00
|
|
|
end
|
|
|
|
|
2020-02-14 09:08:43 +00:00
|
|
|
expose :deployment_cluster, if: -> (build) { build&.deployment&.cluster } do |build, options|
|
|
|
|
# Until data is copied over from deployments.cluster_id, this entity must represent Deployment instead of DeploymentCluster
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/issues/202628
|
|
|
|
DeploymentClusterEntity.represent(build.deployment, options)
|
|
|
|
end
|
|
|
|
|
2020-12-21 00:10:18 +00:00
|
|
|
expose :artifact, if: -> (*) { can?(current_user, :read_job_artifacts, build) } do
|
2020-09-01 18:10:48 +00:00
|
|
|
expose :download_path, if: -> (*) { build.locked_artifacts? || build.artifacts? } do |build|
|
2021-04-08 18:09:32 +00:00
|
|
|
fast_download_project_job_artifacts_path(project, build)
|
2018-08-21 12:47:55 +00:00
|
|
|
end
|
|
|
|
|
2020-09-01 18:10:48 +00:00
|
|
|
expose :browse_path, if: -> (*) { build.locked_artifacts? || build.browsable_artifacts? } do |build|
|
2021-04-08 18:09:32 +00:00
|
|
|
fast_browse_project_job_artifacts_path(project, build)
|
2018-08-21 12:47:55 +00:00
|
|
|
end
|
|
|
|
|
2020-10-05 12:08:47 +00:00
|
|
|
expose :keep_path, if: -> (*) { (build.has_expired_locked_archive_artifacts? || build.has_expiring_archive_artifacts?) && can?(current_user, :update_build, build) } do |build|
|
2021-04-08 18:09:32 +00:00
|
|
|
fast_keep_project_job_artifacts_path(project, build)
|
2018-08-21 12:47:55 +00:00
|
|
|
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
|
2020-08-11 18:10:06 +00:00
|
|
|
|
|
|
|
expose :locked do |build|
|
|
|
|
build.pipeline.artifacts_locked?
|
|
|
|
end
|
2018-08-21 12:47:55 +00:00
|
|
|
end
|
|
|
|
|
2019-05-25 00:08:53 +00:00
|
|
|
expose :report_artifacts,
|
|
|
|
as: :reports,
|
|
|
|
using: JobArtifactReportEntity,
|
|
|
|
if: -> (*) { can?(current_user, :read_build, build) }
|
2019-05-01 22:29:15 +00:00
|
|
|
|
2017-05-29 07:58:20 +00:00
|
|
|
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
|
2017-11-06 13:20:44 +00:00
|
|
|
expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :erase_build, build) } do |build|
|
2017-06-29 17:06:35 +00:00
|
|
|
erase_project_job_path(project, build)
|
2017-05-29 07:58:20 +00:00
|
|
|
end
|
|
|
|
|
2019-03-27 04:01:35 +00:00
|
|
|
expose :failure_reason, if: -> (*) { build.failed? }
|
|
|
|
|
2018-09-05 17:11:13 +00:00
|
|
|
expose :terminal_path, if: -> (*) { can_create_build_terminal? } do |build|
|
|
|
|
terminal_project_job_path(project, build)
|
|
|
|
end
|
|
|
|
|
2017-06-01 19:34:44 +00:00
|
|
|
expose :merge_request, if: -> (*) { can?(current_user, :read_merge_request, build.merge_request) } do
|
2017-05-29 07:58:20 +00:00
|
|
|
expose :iid do |build|
|
|
|
|
build.merge_request.iid
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :path do |build|
|
2017-07-21 11:09:13 +00:00
|
|
|
project_merge_request_path(build.merge_request.project,
|
|
|
|
build.merge_request)
|
2017-05-29 07:58:20 +00:00
|
|
|
end
|
2017-05-23 15:10:07 +00:00
|
|
|
end
|
|
|
|
|
2017-06-02 18:32:37 +00:00
|
|
|
expose :new_issue_path, if: -> (*) { can?(request.current_user, :create_issue, project) && build.failed? } do |build|
|
2017-06-29 17:06:35 +00:00
|
|
|
new_project_issue_path(project, issue: build_failed_issue_options)
|
2017-05-23 15:10:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :raw_path do |build|
|
2017-06-29 17:06:35 +00:00
|
|
|
raw_project_job_path(project, build)
|
2017-05-23 15:10:07 +00:00
|
|
|
end
|
2017-05-26 08:31:42 +00:00
|
|
|
|
2018-09-04 07:51:00 +00:00
|
|
|
expose :trigger, if: -> (*) { build.trigger_request } do
|
|
|
|
expose :trigger_short_token, as: :short_token
|
|
|
|
|
|
|
|
expose :trigger_variables, as: :variables, using: TriggerVariableEntity
|
|
|
|
end
|
|
|
|
|
2018-09-18 07:42:59 +00:00
|
|
|
expose :runners do
|
|
|
|
expose :online do |build|
|
|
|
|
build.any_runners_online?
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :available do |build|
|
2021-04-09 18:09:24 +00:00
|
|
|
build.any_runners_available?
|
2018-09-18 07:42:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :settings_path, if: -> (*) { can_admin_build? } do |build|
|
|
|
|
project_runners_path(project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-26 08:31:42 +00:00
|
|
|
private
|
|
|
|
|
2017-06-02 18:32:37 +00:00
|
|
|
def build_failed_issue_options
|
2017-08-24 16:32:23 +00:00
|
|
|
{ title: "Job Failed ##{build.id}",
|
2018-07-03 08:33:51 +00:00
|
|
|
description: "Job [##{build.id}](#{project_job_url(project, build)}) failed for #{build.sha}:\n" }
|
2017-06-02 18:32:37 +00:00
|
|
|
end
|
|
|
|
|
2017-05-26 08:31:42 +00:00
|
|
|
def current_user
|
|
|
|
request.current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def project
|
|
|
|
build.project
|
|
|
|
end
|
2018-09-05 17:11:13 +00:00
|
|
|
|
|
|
|
def can_create_build_terminal?
|
|
|
|
can?(current_user, :create_build_terminal, build) && build.has_terminal?
|
|
|
|
end
|
2018-09-18 07:42:59 +00:00
|
|
|
|
|
|
|
def can_admin_build?
|
|
|
|
can?(request.current_user, :admin_build, project)
|
|
|
|
end
|
2019-10-17 18:08:05 +00:00
|
|
|
|
|
|
|
def callout_message
|
|
|
|
return super unless build.failure_reason.to_sym == :missing_dependency_failure
|
|
|
|
|
2020-10-14 12:08:58 +00:00
|
|
|
docs_url = "https://docs.gitlab.com/ee/ci/yaml/README.html#dependencies"
|
2019-10-17 18:08:05 +00:00
|
|
|
|
|
|
|
[
|
2020-11-02 21:09:10 +00:00
|
|
|
failure_message,
|
2019-10-17 18:08:05 +00:00
|
|
|
help_message(docs_url).html_safe
|
|
|
|
].join("<br />")
|
|
|
|
end
|
|
|
|
|
|
|
|
def invalid_dependencies
|
|
|
|
build.invalid_dependencies.map(&:name).join(', ')
|
|
|
|
end
|
|
|
|
|
|
|
|
def failure_message
|
|
|
|
_("This job depends on other jobs with expired/erased artifacts: %{invalid_dependencies}") %
|
|
|
|
{ invalid_dependencies: invalid_dependencies }
|
|
|
|
end
|
|
|
|
|
|
|
|
def help_message(docs_url)
|
2020-07-31 21:10:12 +00:00
|
|
|
html_escape(_("Please refer to %{docs_url}")) % { docs_url: "<a href=\"#{docs_url}\">#{html_escape(docs_url)}</a>".html_safe }
|
2019-10-17 18:08:05 +00:00
|
|
|
end
|
2017-05-23 15:10:07 +00:00
|
|
|
end
|
2020-04-12 21:09:39 +00:00
|
|
|
|
|
|
|
BuildDetailsEntity.prepend_if_ee('::EE::BuildDetailEntity')
|