2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-04 11:35:22 -04:00
|
|
|
module EnvironmentHelper
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-11-04 11:35:22 -04:00
|
|
|
def environment_for_build(project, build)
|
|
|
|
return unless build.environment
|
|
|
|
|
2016-11-16 18:23:05 -05:00
|
|
|
project.environments.find_by(name: build.expanded_environment_name)
|
2016-11-04 11:35:22 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-11-04 11:35:22 -04:00
|
|
|
|
|
|
|
def environment_link_for_build(project, build)
|
|
|
|
environment = environment_for_build(project, build)
|
2016-11-16 18:23:05 -05:00
|
|
|
if environment
|
2017-06-29 13:06:35 -04:00
|
|
|
link_to environment.name, project_environment_path(project, environment)
|
2016-11-16 18:23:05 -05:00
|
|
|
else
|
|
|
|
content_tag :span, build.expanded_environment_name
|
|
|
|
end
|
2016-11-04 11:35:22 -04:00
|
|
|
end
|
|
|
|
|
2019-10-16 14:08:01 -04:00
|
|
|
def deployment_path(deployment)
|
2020-07-27 08:09:50 -04:00
|
|
|
[deployment.project, deployment.deployable]
|
2019-10-16 14:08:01 -04:00
|
|
|
end
|
|
|
|
|
2016-12-07 10:27:22 -05:00
|
|
|
def deployment_link(deployment, text: nil)
|
2016-11-04 11:35:22 -04:00
|
|
|
return unless deployment
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
link_label = text || "##{deployment.iid}"
|
2016-12-07 10:27:22 -05:00
|
|
|
|
2019-10-16 14:08:01 -04:00
|
|
|
link_to link_label, deployment_path(deployment)
|
2016-11-30 06:57:38 -05:00
|
|
|
end
|
|
|
|
|
2016-11-16 18:23:05 -05:00
|
|
|
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-10-16 14:08:01 -04:00
|
|
|
|
|
|
|
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')
|
2020-11-18 10:09:08 -05:00
|
|
|
when 'skipped'
|
|
|
|
s_('Deployment|skipped')
|
2019-10-16 14:08:01 -04:00
|
|
|
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-07-21 14:09:27 -04:00
|
|
|
|
|
|
|
def environments_detail_data(user, project, environment)
|
|
|
|
{
|
|
|
|
name: environment.name,
|
|
|
|
id: environment.id,
|
|
|
|
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),
|
|
|
|
environment_metrics_path: environment_metrics_path(environment),
|
|
|
|
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
|
2016-11-04 11:35:22 -04:00
|
|
|
end
|