Commit 4f841b12 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Introduce actual_shared_runners_minutes_limit

parent ceb39b24
...@@ -62,7 +62,7 @@ module GroupsHelper ...@@ -62,7 +62,7 @@ module GroupsHelper
used = group.shared_runners_minutes.to_i used = group.shared_runners_minutes.to_i
if group.shared_runners_minutes_limit_enabled? if group.shared_runners_minutes_limit_enabled?
limit = group.shared_runners_minutes_limit limit = group.actual_shared_runners_minutes_limit
status = group.shared_runners_minutes_used? ? 'over_quota' : 'under_quota' status = group.shared_runners_minutes_used? ? 'over_quota' : 'under_quota'
else else
limit = 'Unlimited' limit = 'Unlimited'
...@@ -77,11 +77,11 @@ module GroupsHelper ...@@ -77,11 +77,11 @@ module GroupsHelper
def group_shared_runner_limits_percent_used(group) def group_shared_runner_limits_percent_used(group)
return 0 unless group.shared_runners_minutes_limit_enabled? return 0 unless group.shared_runners_minutes_limit_enabled?
100 * group.shared_runners_minutes / group.shared_runners_minutes_limit 100 * group.shared_runners_minutes / group.actual_shared_runners_minutes_limit
end end
def group_shared_runner_limits_progress_bar(group) def group_shared_runner_limits_progress_bar(group)
percent = [group.shared_runners_minutes_percent_used, 100].min percent = [group_shared_runner_limits_percent_used(group), 100].min
status = status =
if percent == 100 if percent == 100
......
...@@ -176,19 +176,19 @@ class Namespace < ActiveRecord::Base ...@@ -176,19 +176,19 @@ class Namespace < ActiveRecord::Base
projects.where(shared_runners_enabled: true).any? projects.where(shared_runners_enabled: true).any?
end end
def shared_runners_minutes_limit def actual_shared_runners_minutes_limit
read_attribute(:shared_runners_minutes_limit) || shared_runners_minutes_limit ||
current_application_settings.shared_runners_minutes current_application_settings.shared_runners_minutes
end end
def shared_runners_minutes_limit_enabled? def shared_runners_minutes_limit_enabled?
shared_runners_enabled? && shared_runners_enabled? &&
shared_runners_minutes_limit.nonzero? actual_shared_runners_minutes_limit.nonzero?
end end
def shared_runners_minutes_used? def shared_runners_minutes_used?
shared_runners_minutes_limit_enabled? && shared_runners_minutes_limit_enabled? &&
shared_runners_minutes >= shared_runners_minutes_limit shared_runners_minutes.to_i >= actual_shared_runners_minutes_limit
end end
def full_name def full_name
......
...@@ -31,7 +31,7 @@ class Project < ActiveRecord::Base ...@@ -31,7 +31,7 @@ class Project < ActiveRecord::Base
delegate :shared_runners_minutes, :shared_runners_minutes_last_reset, delegate :shared_runners_minutes, :shared_runners_minutes_last_reset,
to: :project_metrics, allow_nil: true to: :project_metrics, allow_nil: true
delegate :shared_runners_minutes_limit_enabled?, :shared_runners_minutes_limit, delegate :shared_runners_minutes_limit_enabled?, :actual_shared_runners_minutes_limit,
:shared_runners_minutes_used?, to: :namespace :shared_runners_minutes_used?, to: :namespace
default_value_for :archived, false default_value_for :archived, false
......
...@@ -5,5 +5,7 @@ ...@@ -5,5 +5,7 @@
.col-sm-10 .col-sm-10
= f.number_field :shared_runners_minutes_limit, class: 'form-control', min: 0 = f.number_field :shared_runners_minutes_limit, class: 'form-control', min: 0
%span.help-block#shared_runners_minutes_limit_help_block %span.help-block#shared_runners_minutes_limit_help_block
Set the maximum number of minutes that a group can use shared runners in a one month period Set the maximum number of minutes that a group can use shared runners in a one month period.
Set 0 for unlimited.
Set empty to inherit global setting of #{current_application_settings.shared_runners_minutes}.
= link_to icon('question-circle'), help_page_path("user/admin_area/settings/continuous_integration", anchor: "shared-runners-minutes") = link_to icon('question-circle'), help_page_path("user/admin_area/settings/continuous_integration", anchor: "shared-runners-minutes")
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
minutes minutes
.col-sm-6.right .col-sm-6.right
- if @group.shared_runners_minutes_limit_enabled? - if @group.shared_runners_minutes_limit_enabled?
= "#{@group.shared_runners_minutes_percent_used}% used" = "#{group_shared_runner_limits_percent_used(@group)}% used"
- else - else
Unlimited Unlimited
= group_shared_runner_limits_progress_bar(@group) = group_shared_runner_limits_progress_bar(@group)
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
- if @build.project.namespace.shared_runners_minutes_used? - if @build.project.namespace.shared_runners_minutes_used?
- quota_used = @build.project.namespace.shared_runners_minutes.to_i - quota_used = @build.project.namespace.shared_runners_minutes.to_i
- quota_limit = @build.project.namespace.shared_runners_minutes_limit - quota_limit = @build.project.namespace.actual_shared_runners_minutes_limit
.bs-callout.bs-callout-warning .bs-callout.bs-callout-warning
%p %p
You have used all your shared runner minutes You have used all your shared runner minutes
......
...@@ -145,7 +145,6 @@ describe Namespace, models: true do ...@@ -145,7 +145,6 @@ describe Namespace, models: true do
it { expect(nested_group.full_path).to eq("#{group.path}/#{nested_group.path}") } it { expect(nested_group.full_path).to eq("#{group.path}/#{nested_group.path}") }
end end
<<<<<<< HEAD
describe '#shared_runners_enabled?' do describe '#shared_runners_enabled?' do
subject { namespace.shared_runners_enabled? } subject { namespace.shared_runners_enabled? }
...@@ -172,8 +171,8 @@ describe Namespace, models: true do ...@@ -172,8 +171,8 @@ describe Namespace, models: true do
end end
end end
describe '#shared_runners_minutes_limit' do describe '#actual_shared_runners_minutes_limit' do
subject { namespace.shared_runners_minutes_limit } subject { namespace.actual_shared_runners_minutes_limit }
context 'when no limit defined' do context 'when no limit defined' do
it { is_expected.to be_nil } it { is_expected.to be_nil }
...@@ -203,16 +202,28 @@ describe Namespace, models: true do ...@@ -203,16 +202,28 @@ describe Namespace, models: true do
describe '#shared_runners_minutes_limit_enabled?' do describe '#shared_runners_minutes_limit_enabled?' do
subject { namespace.shared_runners_minutes_limit_enabled? } subject { namespace.shared_runners_minutes_limit_enabled? }
context 'when no limit defined' do context 'with project' do
it { is_expected.to be_falsey } let!(:project) do
end create(:empty_project,
namespace: namespace,
shared_runners_enabled: true)
end
context 'when limit is defined' do context 'when no limit defined' do
before do it { is_expected.to be_falsey }
namespace.shared_runners_minutes_limit = 500
end end
it { is_expected.to be_truthy } context 'when limit is defined' do
before do
namespace.shared_runners_minutes_limit = 500
end
it { is_expected.to be_truthy }
end
end
context 'without project' do
it { is_expected.to be_falsey }
end end
end end
...@@ -251,7 +262,9 @@ describe Namespace, models: true do ...@@ -251,7 +262,9 @@ describe Namespace, models: true do
context 'without project' do context 'without project' do
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
======= end
end
describe '#full_name' do describe '#full_name' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:nested_group) { create(:group, parent: group) } let(:nested_group) { create(:group, parent: group) }
...@@ -271,7 +284,6 @@ describe Namespace, models: true do ...@@ -271,7 +284,6 @@ describe Namespace, models: true do
expect(deep_nested_group.parents).to eq([group, nested_group]) expect(deep_nested_group.parents).to eq([group, nested_group])
expect(nested_group.parents).to eq([group]) expect(nested_group.parents).to eq([group])
expect(group.parents).to eq([]) expect(group.parents).to eq([])
>>>>>>> origin-ee/master
end end
end end
end end
...@@ -77,7 +77,7 @@ describe Project, models: true do ...@@ -77,7 +77,7 @@ describe Project, models: true do
it { is_expected.to delegate_method(:shared_runner_minutes).to(:project_metrics) } it { is_expected.to delegate_method(:shared_runner_minutes).to(:project_metrics) }
it { is_expected.to delegate_method(:shared_runner_last_reset).to(:project_metrics) } it { is_expected.to delegate_method(:shared_runner_last_reset).to(:project_metrics) }
it { is_expected.to delegate_method(:shared_runners_minutes_limit).to(:namespace) } it { is_expected.to delegate_method(:actual_shared_runners_minutes_limit).to(:namespace) }
it { is_expected.to delegate_method(:shared_runners_minutes_limit_enabled?).to(:namespace) } it { is_expected.to delegate_method(:shared_runners_minutes_limit_enabled?).to(:namespace) }
it { is_expected.to delegate_method(:shared_runners_minutes_used?).to(:namespace) } it { is_expected.to delegate_method(:shared_runners_minutes_used?).to(:namespace) }
......
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