2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module EnvironmentHelper
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def environment_for_build(project, build)
|
|
|
|
return unless build.environment
|
|
|
|
|
|
|
|
project.environments.find_by(name: build.expanded_environment_name)
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
def environment_link_for_build(project, build)
|
|
|
|
environment = environment_for_build(project, build)
|
|
|
|
if environment
|
2017-09-10 17:25:29 +05:30
|
|
|
link_to environment.name, project_environment_path(project, environment)
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
|
|
|
content_tag :span, build.expanded_environment_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def deployment_path(deployment)
|
2020-10-24 23:57:45 +05:30
|
|
|
[deployment.project, deployment.deployable]
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def deployment_link(deployment, text: nil)
|
|
|
|
return unless deployment
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
link_label = text || "##{deployment.iid}"
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
link_to link_label, deployment_path(deployment)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def last_deployment_link_for_environment_build(project, build)
|
|
|
|
environment = environment_for_build(project, build)
|
|
|
|
return unless environment
|
|
|
|
|
|
|
|
deployment_link(environment.last_deployment)
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
def render_deployment_status(deployment)
|
|
|
|
status = deployment.status
|
|
|
|
|
|
|
|
status_text =
|
|
|
|
case status
|
|
|
|
when 'created'
|
|
|
|
s_('Deployment|created')
|
|
|
|
when 'running'
|
|
|
|
s_('Deployment|running')
|
|
|
|
when 'success'
|
|
|
|
s_('Deployment|success')
|
|
|
|
when 'failed'
|
|
|
|
s_('Deployment|failed')
|
|
|
|
when 'canceled'
|
|
|
|
s_('Deployment|canceled')
|
2021-02-22 17:27:13 +05:30
|
|
|
when 'skipped'
|
|
|
|
s_('Deployment|skipped')
|
2022-03-02 08:16:31 +05:30
|
|
|
when 'blocked'
|
|
|
|
s_('Deployment|blocked')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
klass = "ci-status ci-#{status.dasherize}"
|
|
|
|
text = "#{ci_icon_for_status(status)} #{status_text}".html_safe
|
|
|
|
|
|
|
|
if deployment.deployable
|
|
|
|
link_to(text, deployment_path(deployment), class: klass)
|
|
|
|
else
|
|
|
|
content_tag(:span, text, class: klass)
|
|
|
|
end
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
def environments_detail_data(user, project, environment)
|
|
|
|
{
|
|
|
|
name: environment.name,
|
|
|
|
id: environment.id,
|
2023-03-04 22:38:38 +05:30
|
|
|
project_full_path: project.full_path,
|
2021-10-27 15:23:28 +05:30
|
|
|
external_url: environment.external_url,
|
|
|
|
can_update_environment: can?(current_user, :update_environment, environment),
|
|
|
|
can_destroy_environment: can_destroy_environment?(environment),
|
|
|
|
can_stop_environment: can?(current_user, :stop_environment, environment),
|
|
|
|
can_admin_environment: can?(current_user, :admin_environment, project),
|
2022-06-21 17:19:12 +05:30
|
|
|
environment_metrics_path: project_metrics_dashboard_path(project, environment: environment),
|
2021-10-27 15:23:28 +05:30
|
|
|
environments_fetch_path: project_environments_path(project, format: :json),
|
|
|
|
environment_edit_path: edit_project_environment_path(project, environment),
|
|
|
|
environment_stop_path: stop_project_environment_path(project, environment),
|
|
|
|
environment_delete_path: environment_delete_path(environment),
|
|
|
|
environment_cancel_auto_stop_path: cancel_auto_stop_project_environment_path(project, environment),
|
|
|
|
environment_terminal_path: terminal_project_environment_path(project, environment),
|
|
|
|
has_terminals: environment.has_terminals?,
|
|
|
|
is_environment_available: environment.available?,
|
|
|
|
auto_stop_at: environment.auto_stop_at
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def environments_detail_data_json(user, project, environment)
|
|
|
|
environments_detail_data(user, project, environment).to_json
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|