Module: Ci::RunnersHelper

Includes:
IconsHelper
Defined in:
app/helpers/ci/runners_helper.rb

Constant Summary

Constants included from IconsHelper

IconsHelper::DEFAULT_ICON_SIZE, IconsHelper::VARIANT_CLASSES

Instance Method Summary collapse

Methods included from IconsHelper

#audit_icon, #boolean_to_icon, #custom_icon, #external_snippet_icon, #file_type_icon_class, #gl_loading_icon, #illustrations_path, #sprite_file_icons_path, #sprite_icon, #sprite_icon_path, #visibility_level_icon

Instance Method Details

#admin_runners_app_dataObject



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

def admin_runners_app_data
  data = {
    # Runner install help page is external, located at
    # https://gitlab.com/gitlab-org/gitlab-runner
    runner_install_help_page: 'https://docs.gitlab.com/runner/install/',
    new_runner_path: new_admin_runner_path,
    allow_registration_token: Gitlab::CurrentSettings.allow_runner_registration_token.to_s,
    registration_token: nil,
    online_contact_timeout_secs: ::Ci::Runner::ONLINE_CONTACT_TIMEOUT.to_i,
    stale_timeout_secs: ::Ci::Runner::STALE_TIMEOUT.to_i,
    tag_suggestions_path: tag_list_admin_runners_path(format: :json),
    can_admin_runners: false.to_s
  }

  return data unless current_user.can_admin_all_resources?

  data.merge({
    registration_token: Gitlab::CurrentSettings.runners_registration_token,
    can_admin_runners: true.to_s
  })
end

#admin_runners_fleet_dashboard_dataObject



93
94
95
96
97
98
99
100
# File 'app/helpers/ci/runners_helper.rb', line 93

def admin_runners_fleet_dashboard_data
  {
    admin_runners_path: admin_runners_path,
    new_runner_path: new_admin_runner_path,
    clickhouse_ci_analytics_available: ::Gitlab::ClickHouse.configured?.to_s,
    can_admin_runners: current_user.can_admin_all_resources?.to_s
  }
end

#group_runners_data_attributes(group) ⇒ Object



128
129
130
131
132
133
134
135
136
# File 'app/helpers/ci/runners_helper.rb', line 128

def group_runners_data_attributes(group)
  {
    group_id: group.id,
    group_full_path: group.full_path,
    runner_install_help_page: 'https://docs.gitlab.com/runner/install/',
    online_contact_timeout_secs: ::Ci::Runner::ONLINE_CONTACT_TIMEOUT.to_i,
    stale_timeout_secs: ::Ci::Runner::STALE_TIMEOUT.to_i
  }
end

#group_shared_runners_settings_data(group) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/helpers/ci/runners_helper.rb', line 102

def group_shared_runners_settings_data(group)
  data = {
    group_id: group.id,
    group_name: group.name,
    group_is_empty: (group.projects.empty? && group.children.empty?).to_s,
    shared_runners_setting: group.shared_runners_setting,

    runner_enabled_value: Namespace::SR_ENABLED,
    runner_disabled_value: Namespace::SR_DISABLED_AND_UNOVERRIDABLE,
    runner_allow_override_value: Namespace::SR_DISABLED_AND_OVERRIDABLE,

    parent_shared_runners_setting: group.parent&.shared_runners_setting,
    parent_name: nil,
    parent_settings_path: nil
  }

  if group.parent && can?(current_user, :admin_group, group.parent)
    data.merge!({
      parent_name: group.parent.name,
      parent_settings_path: group_settings_ci_cd_path(group.parent, anchor: 'runners-settings')
    })
  end

  data
end

#project_runners_settings_data(project) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'app/helpers/ci/runners_helper.rb', line 138

def project_runners_settings_data(project)
  can_create_runner_for_group =
    can?(current_user, :create_runners, project.group) || can?(current_user, :register_group_runners, project.group)

  data = {
    project_id: project.id,
    can_create_runner: can?(current_user, :create_runners, project).to_s,
    allow_registration_token: project.namespace.allow_runner_registration_token?.to_s,
    registration_token: can?(current_user, :read_runners_registration_token, project) ? project.runners_token : nil,
    project_full_path: project.full_path,
    new_project_runner_path: new_project_runner_path(project),

    # group runners tab
    can_create_runner_for_group: can_create_runner_for_group.to_s,
    group_runners_path: project&.group ? group_runners_path(project.group) : nil,

    # instance runners tab
    instance_runners_enabled: project.shared_runners_enabled?.to_s,
    instance_runners_disabled_and_unoverridable: (
      project.group&.shared_runners_setting == Namespace::SR_DISABLED_AND_UNOVERRIDABLE
    ).to_s,
    instance_runners_update_path: toggle_shared_runners_project_runners_path(project),
    instance_runners_group_settings_path: nil,
    group_name: nil
  }

  if project.group && can?(current_user, :admin_group, project.group)
    data.merge!({
      instance_runners_group_settings_path: group_settings_ci_cd_path(project.group, anchor: 'runners-settings'),
      group_name: project.group.name
    })
  end

  data
end


58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/ci/runners_helper.rb', line 58

def runner_link(runner)
  display_name = truncate(runner.display_name, length: 15)
  id = "\##{runner.id}"

  if current_user && current_user.admin
    link_to admin_runner_path(runner) do
      display_name + id
    end
  else
    display_name + id
  end
end

#runner_short_name(runner) ⇒ Object



54
55
56
# File 'app/helpers/ci/runners_helper.rb', line 54

def runner_short_name(runner)
  "##{runner.id} (#{runner.short_sha})"
end

#runner_status_icon(runner, size: 16, icon_class: '') ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/ci/runners_helper.rb', line 7

def runner_status_icon(runner, size: 16, icon_class: '')
  status = runner.status
  contacted_at = runner.contacted_at

  title = ''
  icon = 'warning-solid'
  span_class = ''

  case status
  when :online
    title = safe_format(s_("Runners|Runner is online; last contact was %{runner_contact} ago"),
      runner_contact: time_ago_in_words(contacted_at))
    icon = 'status-active'
    span_class = 'gl-text-success'
  when :never_contacted
    title = s_("Runners|Runner has never contacted this instance")
    icon = 'warning-solid'
  when :offline
    title =
      if contacted_at
        safe_format(s_("Runners|Runner is offline; last contact was %{runner_contact} ago"),
          runner_contact: time_ago_in_words(contacted_at))
      else
        s_("Runners|Runner is offline; it has never contacted this instance")
      end

    icon = 'status-waiting'
    span_class = 'gl-text-subtle'
  when :stale
    # runner may have contacted (or not) and be stale: consider both cases.
    title = if contacted_at
              safe_format(s_("Runners|Runner is stale; last contact was %{runner_contact} ago"),
                runner_contact: time_ago_in_words(contacted_at))
            else
              s_("Runners|Runner is stale; it has never contacted this instance")
            end

    icon = 'time-out'
    span_class = 'gl-text-warning'
  end

  (:span, class: span_class, title: title,
    data: { toggle: 'tooltip', container: 'body', testid: 'runner-status-icon', qa_status: status }) do
    sprite_icon(icon, size: size, css_class: icon_class)
  end
end

#toggle_shared_runners_settings_data(project) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'app/helpers/ci/runners_helper.rb', line 174

def toggle_shared_runners_settings_data(project)
  data = {
    is_enabled: project.shared_runners_enabled?.to_s,
    is_disabled_and_unoverridable: (
      project.group&.shared_runners_setting == Namespace::SR_DISABLED_AND_UNOVERRIDABLE
    ).to_s,
    update_path: toggle_shared_runners_project_runners_path(project),
    group_name: nil,
    group_settings_path: nil
  }

  if project.group && can?(current_user, :admin_group, project.group)
    data.merge!({
      group_name: project.group.name,
      group_settings_path: group_settings_ci_cd_path(project.group, anchor: 'runners-settings')
    })
  end

  data
end