Commit e3f90c76 authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch...

Merge branch '212392-show-the-you-re-running-out-of-ci-minutes-warnings-on-relevant-pages-in-gitlab' into 'master'

Show the CI minutes warnings on relevant pages in GitLab

Closes #212392

See merge request gitlab-org/gitlab!31012
parents 77cfb089 29e8f3ca
= content_for :flash_message do
= render_if_exists 'shared/shared_runners_minutes_limit', namespace: @group, classes: [container_class, ("limit-container-width" unless fluid_layout)]
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
= content_for :meta_tags do = content_for :meta_tags do
= auto_discovery_link_tag(:atom, group_url(@group, rss_url_options), title: "#{@group.name} activity") = auto_discovery_link_tag(:atom, group_url(@group, rss_url_options), title: "#{@group.name} activity")
= render partial: 'flash_messages'
%div{ class: [("limit-container-width" unless fluid_layout)] } %div{ class: [("limit-container-width" unless fluid_layout)] }
= render_if_exists 'trials/banner', namespace: @group = render_if_exists 'trials/banner', namespace: @group
......
...@@ -2,6 +2,7 @@ import initGroupSecurityDashboard from 'ee/security_dashboard/group_init'; ...@@ -2,6 +2,7 @@ import initGroupSecurityDashboard from 'ee/security_dashboard/group_init';
import leaveByUrl from '~/namespaces/leave_by_url'; import leaveByUrl from '~/namespaces/leave_by_url';
import initGroupDetails from '~/pages/groups/shared/group_details'; import initGroupDetails from '~/pages/groups/shared/group_details';
import initGroupAnalytics from 'ee/analytics/group_analytics/group_analytics_bundle'; import initGroupAnalytics from 'ee/analytics/group_analytics/group_analytics_bundle';
import initVueAlerts from '~/vue_alerts';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
leaveByUrl('group'); leaveByUrl('group');
...@@ -13,4 +14,5 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -13,4 +14,5 @@ document.addEventListener('DOMContentLoaded', () => {
} }
initGroupAnalytics(); initGroupAnalytics();
initVueAlerts();
}); });
---
title: Show the You're running out of CI minutes warnings on relevant pages in GitLab
merge_request: 31012
author:
type: added
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
require 'spec_helper' require 'spec_helper'
describe 'CI shared runner limits' do describe 'CI shared runner limits' do
let(:user) { create(:user) } using RSpec::Parameterized::TableSyntax
let_it_be(:user) { create(:user) }
let!(:project) { create(:project, :repository, namespace: group, shared_runners_enabled: true) } let!(:project) { create(:project, :repository, namespace: group, shared_runners_enabled: true) }
let(:group) { create(:group) } let(:group) { create(:group) }
...@@ -11,30 +13,65 @@ describe 'CI shared runner limits' do ...@@ -11,30 +13,65 @@ describe 'CI shared runner limits' do
sign_in(user) sign_in(user)
end end
shared_examples 'threshold breached' do context 'when on a project related page' do
before do before do
group.update(shared_runners_minutes_limit: 20) group.add_developer(user)
end end
it 'displays a warning message on pipelines page' do where(:case_name, :percent, :remaining_minutes) do
visit project_pipelines_path(project) 'warning level' | 30 | 4
'danger level' | 5 | 1
expect_quota_exceeded_alert(message)
end end
it 'displays a warning message on project homepage' do with_them do
visit project_path(project) context "when there is a notification and minutes still exist", :js do
let(:message) do
"Group #{group.name} has #{percent}% or less Shared Runner Pipeline minutes remaining. " \
"Once it runs out, no new jobs or pipelines in its projects will run."
end
before do
group.update(shared_runners_minutes_limit: 20)
allow_any_instance_of(EE::Namespace).to receive(:shared_runners_remaining_minutes).and_return(remaining_minutes)
end
it 'displays a warning message on pipelines page' do
visit project_pipelines_path(project)
expect_quota_exceeded_alert(message)
end
it 'displays a warning message on project homepage' do
visit project_path(project)
expect_quota_exceeded_alert(message) expect_quota_exceeded_alert(message)
end
end
end end
end
context 'when project member' do context 'when limit is exceeded', :js do
before do let(:group) { create(:group, :with_used_build_minutes_limit) }
group.add_developer(user) let(:message) do
"Group #{group.name} has exceeded its pipeline minutes quota. " \
"Unless you buy additional pipeline minutes, no new jobs or pipelines in its projects will run."
end
it 'displays a warning message on project homepage' do
visit project_path(project)
expect_quota_exceeded_alert(message)
end
it 'displays a warning message on pipelines page' do
visit project_pipelines_path(project)
expect_quota_exceeded_alert(message)
end
end end
context 'without limit' do context 'when limit not yet exceeded' do
let(:group) { create(:group, :with_not_used_build_minutes_limit) }
it 'does not display a warning message on project homepage' do it 'does not display a warning message on project homepage' do
visit project_path(project) visit project_path(project)
...@@ -47,114 +84,67 @@ describe 'CI shared runner limits' do ...@@ -47,114 +84,67 @@ describe 'CI shared runner limits' do
expect_no_quota_exceeded_alert expect_no_quota_exceeded_alert
end end
end end
end
context 'when limit is defined' do context 'when on a group related page' do
context 'when usage has reached a warning level', :js do let!(:user_pipeline) { create(:ci_pipeline, user: user, project: project) }
it_behaves_like 'threshold breached' do
let(:message) do
"Group #{group.name} has 30% or less Shared Runner Pipeline minutes remaining. " \
"Once it runs out, no new jobs or pipelines in its projects will run."
end
before do
allow_any_instance_of(EE::Namespace).to receive(:shared_runners_remaining_minutes).and_return(4)
end
end
end
context 'when usage has reached a danger level', :js do where(:case_name, :percent, :remaining_minutes) do
it_behaves_like 'threshold breached' do 'warning level' | 30 | 4
let(:message) do 'danger level' | 5 | 1
"Group #{group.name} has 5% or less Shared Runner Pipeline minutes remaining. " \ end
"Once it runs out, no new jobs or pipelines in its projects will run."
end
before do
allow_any_instance_of(EE::Namespace).to receive(:shared_runners_remaining_minutes).and_return(1)
end
end
end
context 'when limit is exceeded', :js do with_them do
let(:group) { create(:group, :with_used_build_minutes_limit) } context "when there is a notification and minutes still exist", :js do
let(:message) do let(:message) do
"Group #{group.name} has exceeded its pipeline minutes quota. " \ "Group #{group.name} has #{percent}% or less Shared Runner Pipeline minutes remaining. " \
"Unless you buy additional pipeline minutes, no new jobs or pipelines in its projects will run." "Once it runs out, no new jobs or pipelines in its projects will run."
end end
it 'displays a warning message on project homepage' do before do
visit project_path(project) group.update(shared_runners_minutes_limit: 20)
allow_any_instance_of(EE::Namespace).to receive(:shared_runners_remaining_minutes).and_return(remaining_minutes)
expect_quota_exceeded_alert(message)
end end
it 'displays a warning message on pipelines page' do it 'displays a warning message on group overview page' do
visit project_pipelines_path(project) visit group_path(group)
expect_quota_exceeded_alert(message) expect_quota_exceeded_alert(message)
end end
end end
end
context 'when limit not yet exceeded' do context 'when limit is exceeded', :js do
let(:group) { create(:group, :with_not_used_build_minutes_limit) } let(:group) { create(:group, :with_used_build_minutes_limit) }
let(:message) do
it 'does not display a warning message on project homepage' do "Group #{group.name} has exceeded its pipeline minutes quota. " \
visit project_path(project) "Unless you buy additional pipeline minutes, no new jobs or pipelines in its projects will run."
expect_no_quota_exceeded_alert
end
it 'does not display a warning message on pipelines page' do
visit project_pipelines_path(project)
expect_no_quota_exceeded_alert
end
end end
context 'when minutes are not yet set' do it 'displays a warning message on group overview page' do
let(:group) { create(:group, :with_build_minutes_limit) } visit group_path(group)
it 'does not display a warning message on project homepage' do
visit project_path(project)
expect_no_quota_exceeded_alert
end
it 'does not display a warning message on pipelines page' do
visit project_pipelines_path(project)
expect_no_quota_exceeded_alert expect_quota_exceeded_alert(message)
end
end end
end end
end
context 'when not a project member' do context 'when limit not yet exceeded' do
let(:group) { create(:group, :with_used_build_minutes_limit) } let(:group) { create(:group, :with_not_used_build_minutes_limit) }
context 'when limit is defined and limit is exceeded' do it 'does not display a warning message on group overview page' do
it 'does not display a warning message on project homepage' do visit group_path(group)
visit project_path(project)
expect_no_quota_exceeded_alert
end
it 'does not display a warning message on pipelines page' do
visit project_pipelines_path(project)
expect_no_quota_exceeded_alert expect_no_quota_exceeded_alert
end end
end end
end end
def expect_quota_exceeded_alert(message = nil) def expect_quota_exceeded_alert(message)
expect(page).to have_selector('.shared-runner-quota-message', count: 1) expect(page).to have_selector('.shared-runner-quota-message', count: 1)
if message page.within('.shared-runner-quota-message') do
page.within('.shared-runner-quota-message') do expect(page).to have_content(message)
expect(page).to have_content(message) expect(page).to have_link 'Buy more Pipeline minutes'
expect(page).to have_link 'Buy more Pipeline minutes'
end
end end
end end
......
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