Module: EnvironmentHelper

Defined in:
app/helpers/environment_helper.rb

Instance Method Summary collapse

Instance Method Details


25
26
27
28
29
30
31
# File 'app/helpers/environment_helper.rb', line 25

def deployment_link(deployment, text: nil)
  return unless deployment

  link_label = text || "##{deployment.iid}"

  link_to link_label, deployment_path(deployment)
end

#deployment_path(deployment) ⇒ Object


21
22
23
# File 'app/helpers/environment_helper.rb', line 21

def deployment_path(deployment)
  [deployment.project, deployment.deployable]
end

#environment_for_build(project, build) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


5
6
7
8
9
# File 'app/helpers/environment_helper.rb', line 5

def environment_for_build(project, build)
  return unless build.environment

  project.environments.find_by(name: build.expanded_environment_name)
end

rubocop: enable CodeReuse/ActiveRecord


12
13
14
15
16
17
18
19
# File 'app/helpers/environment_helper.rb', line 12

def environment_link_for_build(project, build)
  environment = environment_for_build(project, build)
  if environment
    link_to environment.name, project_environment_path(project, environment)
  else
     :span, build.expanded_environment_name
  end
end

#environments_detail_data(user, project, environment) ⇒ Object


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/helpers/environment_helper.rb', line 71

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: project_metrics_dashboard_path(project, environment: 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

#environments_detail_data_json(user, project, environment) ⇒ Object


93
94
95
# File 'app/helpers/environment_helper.rb', line 93

def environments_detail_data_json(user, project, environment)
  environments_detail_data(user, project, environment).to_json
end

33
34
35
36
37
38
# File 'app/helpers/environment_helper.rb', line 33

def last_deployment_link_for_environment_build(project, build)
  environment = environment_for_build(project, build)
  return unless environment

  deployment_link(environment.last_deployment)
end

#render_deployment_status(deployment) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/environment_helper.rb', line 40

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')
    when 'skipped'
      s_('Deployment|skipped')
    when 'blocked'
      s_('Deployment|blocked')
    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
    (:span, text, class: klass)
  end
end