Commit 6c97d4ed authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '207480-move-all-ci-files-under-ci-namespace-2' into 'master'

Move RunnersHelper files under `Ci::` namespace

See merge request gitlab-org/gitlab!36144
parents 654c89e7 e95326d1
# frozen_string_literal: true
module Ci
module RunnersHelper
def runner_status_icon(runner)
status = runner.status
case status
when :not_connected
content_tag :i, nil,
class: "fa fa-warning",
title: "New runner. Has not connected yet"
when :online, :offline, :paused
content_tag :i, nil,
class: "fa fa-circle runner-status-#{status}",
title: "Runner is #{status}, last contact was #{time_ago_in_words(runner.contacted_at)} ago"
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
end
end
Ci::RunnersHelper.prepend_if_ee('EE::Ci::RunnersHelper')
# frozen_string_literal: true
module RunnersHelper
def runner_status_icon(runner)
status = runner.status
case status
when :not_connected
content_tag :i, nil,
class: "fa fa-warning",
title: "New runner. Has not connected yet"
when :online, :offline, :paused
content_tag :i, nil,
class: "fa fa-circle runner-status-#{status}",
title: "Runner is #{status}, last contact was #{time_ago_in_words(runner.contacted_at)} ago"
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
end
RunnersHelper.prepend_if_ee('EE::RunnersHelper')
# frozen_string_literal: true
module EE
module Ci
module RunnersHelper
include ::Gitlab::Utils::StrongMemoize
BUY_PIPELINE_MINUTES_NOTIFICATION_DOT = 'buy_pipeline_minutes_notification_dot'
def show_buy_pipeline_minutes?(project, namespace)
return false unless experiment_enabled?(:ci_notification_dot) || experiment_enabled?(:buy_ci_minutes_version_a)
show_out_of_pipeline_minutes_notification?(project, namespace)
end
def show_pipeline_minutes_notification_dot?(project, namespace)
return false unless experiment_enabled?(:ci_notification_dot)
return false if notification_dot_acknowledged?
show_out_of_pipeline_minutes_notification?(project, namespace)
end
def show_buy_pipeline_with_subtext?(project, namespace)
return false unless experiment_enabled?(:ci_notification_dot)
return false unless notification_dot_acknowledged?
show_out_of_pipeline_minutes_notification?(project, namespace)
end
private
def notification_dot_acknowledged?
strong_memoize(:notification_dot_acknowledged) do
user_dismissed?(BUY_PIPELINE_MINUTES_NOTIFICATION_DOT)
end
end
def show_out_of_pipeline_minutes_notification?(project, namespace)
strong_memoize(:show_out_of_pipeline_minutes_notification) do
next unless project&.persisted? || namespace&.persisted?
::Ci::Minutes::Notification.new(project, namespace).show?(current_user)
end
end
end
end
end
# frozen_string_literal: true
module EE
module RunnersHelper
include ::Gitlab::Utils::StrongMemoize
BUY_PIPELINE_MINUTES_NOTIFICATION_DOT = 'buy_pipeline_minutes_notification_dot'
def show_buy_pipeline_minutes?(project, namespace)
return false unless experiment_enabled?(:ci_notification_dot) || experiment_enabled?(:buy_ci_minutes_version_a)
show_out_of_pipeline_minutes_notification?(project, namespace)
end
def show_pipeline_minutes_notification_dot?(project, namespace)
return false unless experiment_enabled?(:ci_notification_dot)
return false if notification_dot_acknowledged?
show_out_of_pipeline_minutes_notification?(project, namespace)
end
def show_buy_pipeline_with_subtext?(project, namespace)
return false unless experiment_enabled?(:ci_notification_dot)
return false unless notification_dot_acknowledged?
show_out_of_pipeline_minutes_notification?(project, namespace)
end
private
def notification_dot_acknowledged?
strong_memoize(:notification_dot_acknowledged) do
user_dismissed?(BUY_PIPELINE_MINUTES_NOTIFICATION_DOT)
end
end
def show_out_of_pipeline_minutes_notification?(project, namespace)
strong_memoize(:show_out_of_pipeline_minutes_notification) do
next unless project&.persisted? || namespace&.persisted?
::Ci::Minutes::Notification.new(project, namespace).show?(current_user)
end
end
end
end
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
- if show_pipeline_minutes_notification_dot?(project, namespace) - if show_pipeline_minutes_notification_dot?(project, namespace)
- link_class << ' js-follow-link' - link_class << ' js-follow-link'
%li.js-buy-pipeline-minutes-notification-callout{ data: { feature_id: RunnersHelper::BUY_PIPELINE_MINUTES_NOTIFICATION_DOT, %li.js-buy-pipeline-minutes-notification-callout{ data: { feature_id: ::Ci::RunnersHelper::BUY_PIPELINE_MINUTES_NOTIFICATION_DOT,
dismiss_endpoint: user_callouts_path } } dismiss_endpoint: user_callouts_path } }
= link_to path, class: link_class, data: data_attributes do = link_to path, class: link_class, data: data_attributes do
= yield :buy_pipeline_with_subtext = yield :buy_pipeline_with_subtext
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require "spec_helper" require "spec_helper"
RSpec.describe EE::RunnersHelper do RSpec.describe EE::Ci::RunnersHelper do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:namespace) { create(:namespace, owner: user) } let_it_be(:namespace) { create(:namespace, owner: user) }
let_it_be(:project) { create(:project, namespace: namespace) } let_it_be(:project) { create(:project, namespace: namespace) }
......
...@@ -39,7 +39,7 @@ RSpec.describe 'layouts/header/_current_user_dropdown' do ...@@ -39,7 +39,7 @@ RSpec.describe 'layouts/header/_current_user_dropdown' do
expect(subject).to have_link('Buy Pipeline minutes') expect(subject).to have_link('Buy Pipeline minutes')
expect(subject).to have_content('One of your groups is running out') expect(subject).to have_content('One of your groups is running out')
expect(subject).to have_selector('.js-follow-link') expect(subject).to have_selector('.js-follow-link')
expect(subject).to have_selector("[data-feature-id='#{RunnersHelper::BUY_PIPELINE_MINUTES_NOTIFICATION_DOT}']") expect(subject).to have_selector("[data-feature-id='#{::Ci::RunnersHelper::BUY_PIPELINE_MINUTES_NOTIFICATION_DOT}']")
expect(subject).to have_selector("[data-dismiss-endpoint='#{user_callouts_path}']") expect(subject).to have_selector("[data-dismiss-endpoint='#{user_callouts_path}']")
end end
end end
...@@ -51,7 +51,7 @@ RSpec.describe 'layouts/header/_current_user_dropdown' do ...@@ -51,7 +51,7 @@ RSpec.describe 'layouts/header/_current_user_dropdown' do
expect(subject).to have_link('Buy Pipeline minutes') expect(subject).to have_link('Buy Pipeline minutes')
expect(subject).to have_content('One of your groups is running out') expect(subject).to have_content('One of your groups is running out')
expect(subject).not_to have_selector('.js-follow-link') expect(subject).not_to have_selector('.js-follow-link')
expect(subject).not_to have_selector("[data-feature-id='#{RunnersHelper::BUY_PIPELINE_MINUTES_NOTIFICATION_DOT}']") expect(subject).not_to have_selector("[data-feature-id='#{::Ci::RunnersHelper::BUY_PIPELINE_MINUTES_NOTIFICATION_DOT}']")
expect(subject).not_to have_selector("[data-dismiss-endpoint='#{user_callouts_path}']") expect(subject).not_to have_selector("[data-dismiss-endpoint='#{user_callouts_path}']")
end end
end end
......
...@@ -13,7 +13,7 @@ module QA ...@@ -13,7 +13,7 @@ module QA
## ##
# TODO, phase-out CSS classes added in Ruby helpers. # TODO, phase-out CSS classes added in Ruby helpers.
# #
view 'app/helpers/runners_helper.rb' do view 'app/helpers/ci/runners_helper.rb' do
# rubocop:disable Lint/InterpolationCheck # rubocop:disable Lint/InterpolationCheck
element :runner_status, 'runner-status-#{status}' # rubocop:disable QA/ElementWithPattern element :runner_status, 'runner-status-#{status}' # rubocop:disable QA/ElementWithPattern
# rubocop:enable Lint/InterpolationCheck # rubocop:enable Lint/InterpolationCheck
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe RunnersHelper do RSpec.describe Ci::RunnersHelper do
it "returns - not contacted yet" do it "returns - not contacted yet" do
runner = FactoryBot.build :ci_runner runner = FactoryBot.build :ci_runner
expect(runner_status_icon(runner)).to include("not connected yet") expect(runner_status_icon(runner)).to include("not connected yet")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment