2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
class BuildDetailsEntity < Ci::JobEntity
|
|
|
|
expose :coverage, :erased_at, :finished_at, :duration
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :tag_list, as: :tags
|
2018-12-05 23:21:45 +05:30
|
|
|
expose :has_trace?, as: :has_trace
|
|
|
|
expose :stage
|
2018-12-13 13:39:08 +05:30
|
|
|
expose :stuck?, as: :stuck
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :user, using: UserEntity
|
|
|
|
expose :runner, using: RunnerEntity
|
2019-09-04 21:01:54 +05:30
|
|
|
expose :metadata, using: BuildMetadataEntity
|
2021-03-11 19:13:27 +05:30
|
|
|
expose :pipeline, using: Ci::PipelineEntity
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expose :deployment_status, if: -> (*) { build.starts_environment? } do
|
|
|
|
expose :deployment_status, as: :status
|
2019-09-04 21:01:54 +05:30
|
|
|
expose :persisted_environment, as: :environment do |build, options|
|
|
|
|
options.merge(deployment_details: false).yield_self do |opts|
|
|
|
|
EnvironmentEntity.represent(build.persisted_environment, opts)
|
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
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
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expose :artifact, if: -> (*) { can?(current_user, :read_job_artifacts, build) } do
|
2020-11-24 15:15:51 +05:30
|
|
|
expose :download_path, if: -> (*) { build.locked_artifacts? || build.artifacts? } do |build|
|
2021-04-29 21:17:54 +05:30
|
|
|
fast_download_project_job_artifacts_path(project, build)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expose :browse_path, if: -> (*) { build.locked_artifacts? || build.browsable_artifacts? } do |build|
|
2021-04-29 21:17:54 +05:30
|
|
|
fast_browse_project_job_artifacts_path(project, build)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
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-29 21:17:54 +05:30
|
|
|
fast_keep_project_job_artifacts_path(project, build)
|
2018-11-20 20:47:30 +05:30
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expose :locked do |build|
|
|
|
|
build.pipeline.artifacts_locked?
|
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
expose :report_artifacts,
|
|
|
|
as: :reports,
|
|
|
|
using: JobArtifactReportEntity,
|
|
|
|
if: -> (*) { can?(current_user, :read_build, build) }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
|
2018-03-17 18:26:18 +05:30
|
|
|
expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :erase_build, build) } do |build|
|
2017-09-10 17:25:29 +05:30
|
|
|
erase_project_job_path(project, build)
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
expose :failure_reason, if: -> (*) { build.failed? }
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
expose :terminal_path, if: -> (*) { can_create_build_terminal? } do |build|
|
|
|
|
terminal_project_job_path(project, build)
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :merge_request, if: -> (*) { can?(current_user, :read_merge_request, build.merge_request) } do
|
|
|
|
expose :iid do |build|
|
|
|
|
build.merge_request.iid
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :path do |build|
|
|
|
|
project_merge_request_path(build.merge_request.project,
|
|
|
|
build.merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
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|
|
2021-04-29 21:17:54 +05:30
|
|
|
build.any_runners_available?
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :settings_path, if: -> (*) { can_admin_build? } do |build|
|
|
|
|
project_runners_path(project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
private
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
alias_method :build, :object
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def build_failed_issue_options
|
2018-03-17 18:26:18 +05:30
|
|
|
{ title: "Job Failed ##{build.id}",
|
2018-11-08 19:23:39 +05:30
|
|
|
description: "Job [##{build.id}](#{project_job_url(project, build)}) failed for #{build.sha}:\n" }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
request.current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def project
|
|
|
|
build.project
|
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
def can_create_build_terminal?
|
|
|
|
can?(current_user, :create_build_terminal, build) && build.has_terminal?
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
def can_admin_build?
|
|
|
|
can?(request.current_user, :admin_build, project)
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
def callout_message
|
|
|
|
return super unless build.failure_reason.to_sym == :missing_dependency_failure
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
docs_url = "https://docs.gitlab.com/ee/ci/yaml/index.html#dependencies"
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
[
|
2020-11-05 12:06:23 +05:30
|
|
|
failure_message,
|
2019-12-21 20:55:43 +05:30
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
html_escape(_("Please refer to %{docs_url}")) % { docs_url: "<a href=\"#{docs_url}\">#{html_escape(docs_url)}</a>".html_safe }
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
BuildDetailsEntity.prepend_mod_with('BuildDetailEntity')
|