2020-07-13 14:09:16 -04:00
# frozen_string_literal: true
module Ci
module RunnersHelper
2020-10-29 11:09:12 -04:00
include IconsHelper
2021-04-14 05:09:14 -04:00
def runner_status_icon ( runner , size : 16 , icon_class : '' )
2020-07-13 14:09:16 -04:00
status = runner . status
2022-03-23 14:08:47 -04:00
contacted_at = runner . contacted_at
2021-04-14 05:09:14 -04:00
title = ''
icon = 'warning-solid'
span_class = ''
2020-07-13 14:09:16 -04:00
case status
2021-11-05 02:13:16 -04:00
when :online
2022-03-23 14:08:47 -04:00
title = 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-green-500'
2021-12-10 13:14:42 -05:00
when :not_connected , :never_contacted
2022-03-23 14:08:47 -04:00
title = s_ ( " Runners|Runner has never contacted this instance " )
2021-04-14 05:09:14 -04:00
icon = 'warning-solid'
when :offline
2022-03-23 14:08:47 -04:00
title = s_ ( " Runners|Runner is offline; last contact was %{runner_contact} ago " ) % { runner_contact : time_ago_in_words ( contacted_at ) }
2021-04-14 05:09:14 -04:00
icon = 'status-failed'
span_class = 'gl-text-red-500'
2022-03-23 14:08:47 -04:00
when :stale
# runner may have contacted (or not) and be stale: consider both cases.
title = contacted_at ? s_ ( " Runners|Runner is stale; last contact was %{runner_contact} ago " ) % { runner_contact : time_ago_in_words ( contacted_at ) } : s_ ( " Runners|Runner is stale; it has never contacted this instance " )
icon = 'warning-solid'
2021-04-14 05:09:14 -04:00
end
2020-07-13 14:09:16 -04:00
2021-04-14 05:09:14 -04:00
content_tag ( :span , class : span_class , title : title , data : { toggle : 'tooltip' , container : 'body' , testid : 'runner_status_icon' , qa_selector : " runner_status_ #{ status } _content " } ) do
sprite_icon ( icon , size : size , css_class : icon_class )
2020-07-13 14:09:16 -04:00
end
end
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
# Due to inability of performing sorting of runners by cached "contacted_at" values we have to show uncached values if sorting by "contacted_asc" is requested.
# Please refer to the following issue for more details: https://gitlab.com/gitlab-org/gitlab-foss/issues/55920
def runner_contacted_at ( runner )
if params [ :sort ] == 'contacted_asc'
runner . uncached_contacted_at
else
runner . contacted_at
end
end
2020-10-08 11:08:17 -04:00
2021-11-16 16:12:05 -05:00
def admin_runners_data_attributes
{
# 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/' ,
2022-03-31 11:08:32 -04:00
registration_token : Gitlab :: CurrentSettings . runners_registration_token ,
online_contact_timeout_secs : :: Ci :: Runner :: ONLINE_CONTACT_TIMEOUT . to_i ,
stale_timeout_secs : :: Ci :: Runner :: STALE_TIMEOUT . to_i
2021-11-16 16:12:05 -05:00
}
end
2020-10-08 11:08:17 -04:00
def group_shared_runners_settings_data ( group )
{
update_path : api_v4_groups_path ( id : group . id ) ,
2022-05-04 11:09:12 -04:00
shared_runners_setting : group . shared_runners_setting ,
parent_shared_runners_setting : group . parent & . shared_runners_setting ,
runner_enabled_value : Namespace :: SR_ENABLED ,
runner_disabled_value : Namespace :: SR_DISABLED_AND_UNOVERRIDABLE ,
runner_allow_override_value : Namespace :: SR_DISABLED_WITH_OVERRIDE
2020-10-08 11:08:17 -04:00
}
end
2020-12-11 04:09:48 -05:00
2021-08-25 08:11:32 -04:00
def group_runners_data_attributes ( group )
{
registration_token : group . runners_token ,
group_id : group . id ,
group_full_path : group . full_path ,
2022-03-31 11:08:32 -04:00
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
2021-08-25 08:11:32 -04:00
}
end
2020-12-11 04:09:48 -05:00
def toggle_shared_runners_settings_data ( project )
{
is_enabled : " #{ project . shared_runners_enabled? } " ,
2021-10-13 11:12:51 -04:00
is_disabled_and_unoverridable : " #{ project . group & . shared_runners_setting == Namespace :: SR_DISABLED_AND_UNOVERRIDABLE } " ,
2020-12-11 04:09:48 -05:00
update_path : toggle_shared_runners_project_runners_path ( project )
}
end
2020-07-13 14:09:16 -04:00
end
end
2021-05-11 17:10:21 -04:00
Ci :: RunnersHelper . prepend_mod_with ( 'Ci::RunnersHelper' )