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')
|
|
|
|
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
|
2016-11-04 11:35:22 -04:00
|
|
|
end
|