From 2b5079efdb7c4e7d5a607d95747ddeb0b8af9678 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 15 May 2023 21:07:42 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- app/presenters/ml/candidate_details_presenter.rb | 88 ++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 app/presenters/ml/candidate_details_presenter.rb (limited to 'app/presenters') diff --git a/app/presenters/ml/candidate_details_presenter.rb b/app/presenters/ml/candidate_details_presenter.rb new file mode 100644 index 00000000000..58ec2aee471 --- /dev/null +++ b/app/presenters/ml/candidate_details_presenter.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +module Ml + class CandidateDetailsPresenter + include Rails.application.routes.url_helpers + + def initialize(candidate) + @candidate = candidate + end + + def present + data = { + candidate: { + info: { + iid: candidate.iid, + eid: candidate.eid, + path_to_artifact: link_to_artifact, + experiment_name: candidate.experiment.name, + path_to_experiment: link_to_experiment, + path: link_to_details, + status: candidate.status, + ci_job: job_info + }, + params: candidate.params, + metrics: candidate.latest_metrics, + metadata: candidate.metadata + } + } + + Gitlab::Json.generate(data) + end + + private + + attr_reader :candidate + + def job_info + return unless candidate.from_ci? + + build = candidate.ci_build + + { + path: project_job_path(build.project, build), + name: build.name, + **user_info(build.user) || {}, + **mr_info(build.pipeline.merge_request) || {} + } + end + + def user_info(user) + return unless user + + { + user: { + path: user_path(user), + username: user.username + } + } + end + + def mr_info(mr) + return unless mr + + { + merge_request: { + path: project_merge_request_path(mr.project, mr), + title: mr.title + } + } + end + + def link_to_artifact + artifact = candidate.artifact + + return unless artifact.present? + + project_package_path(candidate.project, artifact) + end + + def link_to_details + project_ml_candidate_path(candidate.project, candidate.iid) + end + + def link_to_experiment + project_ml_experiment_path(candidate.project, candidate.experiment.iid) + end + end +end -- cgit v1.2.3