debian-mirror-gitlab/lib/gitlab/data_builder/deployment.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.6 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
module Gitlab
module DataBuilder
module Deployment
extend self
2022-08-13 15:12:31 +05:30
# NOTE: Time-sensitive attributes should be explicitly passed as argument instead of reading from database.
def build(deployment, status, status_changed_at)
2019-12-26 22:10:19 +05:30
# Deployments will not have a deployable when created using the API.
deployable_url =
if deployment.deployable
Gitlab::UrlBuilder.build(deployment.deployable)
end
2022-06-21 17:19:12 +05:30
commit_url =
if (commit = deployment.commit)
Gitlab::UrlBuilder.build(commit)
end
user_url =
if deployment.deployed_by
Gitlab::UrlBuilder.build(deployment.deployed_by)
end
2022-08-13 15:12:31 +05:30
# `status` argument could be `nil` during the upgrade. We can remove `deployment.status` in GitLab 15.5.
# See https://docs.gitlab.com/ee/development/multi_version_compatibility.html for more info.
deployment_status = status || deployment.status
2019-07-31 22:56:46 +05:30
{
object_kind: 'deployment',
2022-08-13 15:12:31 +05:30
status: deployment_status,
2021-06-08 01:23:25 +05:30
status_changed_at: status_changed_at,
2021-10-27 15:23:28 +05:30
deployment_id: deployment.id,
2019-07-31 22:56:46 +05:30
deployable_id: deployment.deployable_id,
2019-12-26 22:10:19 +05:30
deployable_url: deployable_url,
2019-07-31 22:56:46 +05:30
environment: deployment.environment.name,
project: deployment.project.hook_attrs,
short_sha: deployment.short_sha,
2022-06-21 17:19:12 +05:30
user: deployment.deployed_by&.hook_attrs,
user_url: user_url,
commit_url: commit_url,
commit_title: deployment.commit_title,
2022-03-02 08:16:31 +05:30
ref: deployment.ref
2019-07-31 22:56:46 +05:30
}
end
end
end
end