Commit 0bfcf6c3 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '292445-no-quota-for-subgroup' into 'master'

Remove quota data for subgroups

See merge request gitlab-org/gitlab!50163
parents c7fe7d80 9148fd24
......@@ -19,12 +19,7 @@ module Ci
# Status of the monthly allowance being used.
def monthly_minutes_report
if enabled?
status = monthly_minutes_used_up? ? :over_quota : :under_quota
Report.new(monthly_minutes_used, monthly_minutes, status)
else
Report.new(monthly_minutes_used, 'Unlimited', :disabled)
end
Report.new(monthly_minutes_used, minutes_limit, report_status)
end
def monthly_percent_used
......@@ -65,12 +60,28 @@ module Ci
100 * total_minutes_remaining.to_i / total_minutes
end
private
def namespace_eligible?
namespace.root? && namespace.any_project_with_shared_runners_enabled?
end
private
def minutes_limit
return monthly_minutes if enabled?
if namespace_eligible?
_('Unlimited')
else
_('Not supported')
end
end
def report_status
return :disabled unless enabled?
monthly_minutes_used_up? ? :over_quota : :under_quota
end
def total_minutes_remaining
[total_minutes.to_i - total_minutes_used, 0].max
end
......
- namespace = local_assigns.fetch(:namespace)
- minutes_quota = namespace.ci_minutes_quota
- if namespace.any_project_with_shared_runners_enabled?
- if minutes_quota.namespace_eligible?
%li
%span.light Pipeline minutes quota:
%span.light= _('Pipeline minutes quota:')
%strong
= ci_minutes_report(minutes_quota.monthly_minutes_report)
= link_to sprite_icon('question-o'), help_page_path('user/admin_area/settings/continuous_integration', anchor: 'shared-runners-pipeline-minutes-quota'), target: '_blank'
---
title: Remove quota data for subgroups
merge_request: 50163
author:
type: fixed
......@@ -25,7 +25,7 @@ RSpec.describe 'Profile > Usage Quota' do
describe 'shared runners use' do
where(:shared_runners_enabled, :used, :quota, :usage_class, :usage_text) do
false | 300 | 500 | 'success' | '300 / Unlimited minutes 0% used'
false | 300 | 500 | 'success' | '300 / Not supported minutes 0% used'
true | 300 | nil | 'success' | '300 / Unlimited minutes Unlimited'
true | 300 | 500 | 'success' | '300 / 500 minutes 60% used'
true | 1000 | 500 | 'danger' | '1000 / 500 minutes 200% used'
......
......@@ -55,11 +55,16 @@ RSpec.describe EE::NamespacesHelper do
describe 'rendering monthly minutes report' do
let(:report) { quota.monthly_minutes_report }
context "when it's unlimited" do
context "when ci minutes quota is not enabled" do
before do
allow(user_group).to receive(:shared_runners_minutes_limit_enabled?).and_return(false)
end
context 'and the namespace is eligible for unlimited' do
before do
allow(quota).to receive(:namespace_eligible?).and_return(true)
end
it 'returns Unlimited for the limit section' do
expect(helper.ci_minutes_report(report)).to match(%r{0 / Unlimited})
end
......@@ -71,6 +76,17 @@ RSpec.describe EE::NamespacesHelper do
end
end
context 'and the namespace is not eligible for unlimited' do
before do
allow(quota).to receive(:namespace_eligible?).and_return(false)
end
it 'returns Not supported for the limit section' do
expect(helper.ci_minutes_report(report)).to match(%r{0 / Not supported})
end
end
end
context "when it's limited" do
before do
allow(user_group).to receive(:any_project_with_shared_runners_enabled?).and_return(true)
......
......@@ -4,14 +4,14 @@ require 'spec_helper'
RSpec.describe Ci::Minutes::Quota do
using RSpec::Parameterized::TableSyntax
let_it_be(:namespace) do
let_it_be_with_reload(:namespace) do
create(:namespace, namespace_statistics: create(:namespace_statistics))
end
let(:quota) { described_class.new(namespace) }
describe '#enabled?' do
let_it_be(:project) { create(:project, namespace: namespace) }
let(:project) { create(:project, namespace: namespace) }
subject { quota.enabled? }
......@@ -64,11 +64,27 @@ RSpec.describe Ci::Minutes::Quota do
end
describe '#monthly_minutes_report' do
context 'when unlimited' do
context 'when the quota is not enabled' do
before do
allow(quota).to receive(:enabled?).and_return(false)
allow(quota).to receive(:namespace_eligible?).and_return(namespace_eligible)
end
context 'when the namespace is not eligible' do
let(:namespace_eligible) { false }
it 'returns not supported report with no usage' do
report = quota.monthly_minutes_report
expect(report.limit).to eq 'Not supported'
expect(report.used).to eq 0
expect(report.status).to eq :disabled
end
end
context 'when the namespace is eligible' do
let(:namespace_eligible) { true }
context 'when minutes are not used' do
it 'returns unlimited report with no usage' do
report = quota.monthly_minutes_report
......@@ -93,6 +109,7 @@ RSpec.describe Ci::Minutes::Quota do
end
end
end
end
context 'when limited' do
before do
......@@ -373,4 +390,38 @@ RSpec.describe Ci::Minutes::Quota do
it { is_expected.to eq(result) }
end
end
describe '#namespace_eligible?' do
subject { quota.namespace_eligible? }
context 'when namespace is a subgroup' do
it 'is false' do
allow(namespace).to receive(:root?).and_return(false)
expect(subject).to be_falsey
end
end
context 'when namespace is root' do
before do
create(:project, namespace: namespace, shared_runners_enabled: shared_runners_enabled)
end
context 'and it has a project without any shared runner enabled' do
let(:shared_runners_enabled) { false }
it 'is false' do
expect(subject).to be_falsey
end
end
context 'and it has a project with shared runner enabled' do
let(:shared_runners_enabled) { true }
it 'is true' do
expect(subject).to be_truthy
end
end
end
end
end
......@@ -19121,6 +19121,9 @@ msgstr ""
msgid "Not started"
msgstr ""
msgid "Not supported"
msgstr ""
msgid "Note"
msgstr ""
......@@ -20320,6 +20323,9 @@ msgstr ""
msgid "Pipeline minutes quota"
msgstr ""
msgid "Pipeline minutes quota:"
msgstr ""
msgid "Pipeline ran in fork of project"
msgstr ""
......
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