Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b7fa38f8
Commit
b7fa38f8
authored
Dec 10, 2020
by
Fabio Pitino
Committed by
Nick Thomas
Dec 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move actual_shared_runners_minutes_limit to Ci::Minutes::Quota
Moved to Ci::Minutes::Quota#total_minutes
parent
53e51823
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
79 additions
and
65 deletions
+79
-65
ee/app/models/ci/minutes/quota.rb
ee/app/models/ci/minutes/quota.rb
+4
-6
ee/app/models/ee/namespace.rb
ee/app/models/ee/namespace.rb
+1
-11
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+1
-1
ee/app/serializers/ee/build_detail_entity.rb
ee/app/serializers/ee/build_detail_entity.rb
+2
-2
ee/app/views/admin/projects/_shared_runner_status.html.haml
ee/app/views/admin/projects/_shared_runner_status.html.haml
+1
-1
ee/spec/models/ci/minutes/notification_spec.rb
ee/spec/models/ci/minutes/notification_spec.rb
+1
-1
ee/spec/models/ci/minutes/quota_spec.rb
ee/spec/models/ci/minutes/quota_spec.rb
+22
-0
ee/spec/models/ee/namespace_spec.rb
ee/spec/models/ee/namespace_spec.rb
+0
-42
ee/spec/models/project_spec.rb
ee/spec/models/project_spec.rb
+1
-1
ee/spec/serializers/ee/build_details_entity_spec.rb
ee/spec/serializers/ee/build_details_entity_spec.rb
+46
-0
No files found.
ee/app/models/ci/minutes/quota.rb
View file @
b7fa38f8
...
...
@@ -48,6 +48,10 @@ module Ci
total_minutes_used
>=
total_minutes
end
def
total_minutes
@total_minutes
||=
monthly_minutes
+
purchased_minutes
end
def
total_minutes_used
@total_minutes_used
||=
namespace
.
shared_runners_seconds
.
to_i
/
60
end
...
...
@@ -97,12 +101,6 @@ module Ci
purchased_minutes
>
0
end
# TODO: maps to Namespace#actual_shared_runners_minutes_limit(include_extra: true)
def
total_minutes
@total_minutes
||=
monthly_minutes
+
purchased_minutes
end
# TODO: maps to Namespace#actual_shared_runners_minutes_limit(include_extra: false)
def
monthly_minutes
@monthly_minutes
||=
(
namespace
.
shared_runners_minutes_limit
||
::
Gitlab
::
CurrentSettings
.
shared_runners_minutes
).
to_i
end
...
...
ee/app/models/ee/namespace.rb
View file @
b7fa38f8
...
...
@@ -249,20 +249,10 @@ module EE
!
has_parent?
end
def
actual_shared_runners_minutes_limit
(
include_extra:
true
)
extra_minutes
=
include_extra
?
extra_shared_runners_minutes_limit
.
to_i
:
0
if
shared_runners_minutes_limit
shared_runners_minutes_limit
+
extra_minutes
else
::
Gitlab
::
CurrentSettings
.
shared_runners_minutes
+
extra_minutes
end
end
def
shared_runners_minutes_limit_enabled?
shared_runner_minutes_supported?
&&
any_project_with_shared_runners_enabled?
&&
actual_shared_runners_minutes_limit
.
nonzero?
ci_minutes_quota
.
total_minutes
.
nonzero?
end
def
any_project_with_shared_runners_enabled?
...
...
ee/app/models/ee/project.rb
View file @
b7fa38f8
...
...
@@ -184,7 +184,7 @@ module EE
delegate
:shared_runners_minutes
,
:shared_runners_seconds
,
:shared_runners_seconds_last_reset
,
to: :statistics
,
allow_nil:
true
delegate
:
actual_shared_runners_minutes_limit
,
to: :shared_runners_limit_namespace
delegate
:
ci_minutes_quota
,
to: :shared_runners_limit_namespace
delegate
:last_update_succeeded?
,
:last_update_failed?
,
:ever_updated_successfully?
,
:hard_failed?
,
...
...
ee/app/serializers/ee/build_detail_entity.rb
View file @
b7fa38f8
...
...
@@ -8,11 +8,11 @@ module EE
expose
:runners
do
expose
:quota
,
if:
->
(
*
)
{
project
.
shared_runners_minutes_limit_enabled?
}
do
expose
:used
do
|
runner
|
::
Ci
::
Minutes
::
Quota
.
new
(
project
.
shared_runners_limit_namespace
)
.
total_minutes_used
project
.
ci_minutes_quota
.
total_minutes_used
end
expose
:limit
do
|
runner
|
project
.
shared_runners_limit_namespace
.
actual_shared_runners_minutes_limit
.
to_i
project
.
ci_minutes_quota
.
total_minutes
end
end
end
...
...
ee/app/views/admin/projects/_shared_runner_status.html.haml
View file @
b7fa38f8
...
...
@@ -5,7 +5,7 @@
-
if
project
.
shared_runners_enabled?
Enabled
-
if
project
.
shared_runners_minutes_limit_enabled?
-
limit
=
project
.
actual_shared_runners_minutes_limit
.
to_i
-
limit
=
project
.
ci_minutes_quota
.
total_minutes
(Limited to
#{
limit
}
pipeline minutes per month)
-
else
(Unlimited pipeline minutes)
...
...
ee/spec/models/ci/minutes/notification_spec.rb
View file @
b7fa38f8
...
...
@@ -6,7 +6,7 @@ RSpec.describe Ci::Minutes::Notification do
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:shared_runners_enabled
)
{
true
}
let!
(
:project
)
{
create
(
:project
,
:repository
,
namespace:
group
,
shared_runners_enabled:
shared_runners_enabled
)
}
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:group
,
refind:
true
)
{
create
(
:group
)
}
let
(
:injected_group
)
{
group
}
let
(
:injected_project
)
{
project
}
...
...
ee/spec/models/ci/minutes/quota_spec.rb
View file @
b7fa38f8
...
...
@@ -256,6 +256,28 @@ RSpec.describe Ci::Minutes::Quota do
end
end
describe
'#total_minutes'
do
subject
{
quota
.
total_minutes
}
where
(
:namespace_monthly_limit
,
:application_monthly_limit
,
:purchased_minutes
,
:result
)
do
20
|
100
|
30
|
50
nil
|
100
|
30
|
130
20
|
100
|
0
|
20
0
|
0
|
30
|
30
nil
|
0
|
30
|
30
end
with_them
do
before
do
namespace
.
shared_runners_minutes_limit
=
namespace_monthly_limit
allow
(
::
Gitlab
::
CurrentSettings
).
to
receive
(
:shared_runners_minutes
).
and_return
(
application_monthly_limit
)
allow
(
namespace
).
to
receive
(
:extra_shared_runners_minutes_limit
).
and_return
(
purchased_minutes
)
end
it
{
is_expected
.
to
eq
(
result
)
}
end
end
describe
'#total_minutes_used'
do
subject
{
quota
.
total_minutes_used
}
...
...
ee/spec/models/ee/namespace_spec.rb
View file @
b7fa38f8
...
...
@@ -644,48 +644,6 @@ RSpec.describe Namespace do
end
end
describe
'#actual_shared_runners_minutes_limit'
do
subject
{
namespace
.
actual_shared_runners_minutes_limit
}
context
'when no limit defined'
do
it
{
is_expected
.
to
be_zero
}
end
context
'when application settings limit is set'
do
before
do
stub_application_setting
(
shared_runners_minutes:
1000
)
end
it
'returns global limit'
do
is_expected
.
to
eq
(
1000
)
end
context
'when namespace limit is set'
do
before
do
namespace
.
shared_runners_minutes_limit
=
500
end
it
'returns namespace limit'
do
is_expected
.
to
eq
(
500
)
end
end
context
'when extra minutes limit is set'
do
before
do
namespace
.
update_attribute
(
:extra_shared_runners_minutes_limit
,
100
)
end
it
'returns the extra minutes by default'
do
is_expected
.
to
eq
(
1100
)
end
it
'can exclude the extra minutes if required'
do
expect
(
namespace
.
actual_shared_runners_minutes_limit
(
include_extra:
false
)).
to
eq
(
1000
)
end
end
end
end
describe
'#shared_runner_minutes_supported?'
do
subject
{
namespace
.
shared_runner_minutes_supported?
}
...
...
ee/spec/models/project_spec.rb
View file @
b7fa38f8
...
...
@@ -14,7 +14,7 @@ RSpec.describe Project do
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds_last_reset
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:
actual_shared_runners_minutes_limit
).
to
(
:shared_runners_limit_namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:
ci_minutes_quota
).
to
(
:shared_runners_limit_namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_limit_enabled?
).
to
(
:shared_runners_limit_namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:closest_gitlab_subscription
).
to
(
:namespace
)
}
...
...
ee/spec/serializers/ee/build_details_entity_spec.rb
0 → 100644
View file @
b7fa38f8
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
BuildDetailsEntity
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
namespace
)
}
let
(
:request
)
{
double
(
'request'
,
project:
project
)
}
let
(
:build
)
{
create
(
:ci_build
,
project:
project
)
}
let
(
:entity
)
do
described_class
.
new
(
build
,
request:
request
,
current_user:
user
,
project:
project
)
end
subject
{
entity
.
as_json
}
before
do
allow
(
request
).
to
receive
(
:current_user
).
and_return
(
user
)
allow
(
namespace
).
to
receive
(
:shared_runners_seconds
).
and_return
(
800
.
minutes
)
end
context
'when namespace has CI minutes limit enabled'
do
before
do
allow
(
namespace
).
to
receive
(
:shared_runners_minutes_limit
).
and_return
(
1000
)
end
it
'contains CI minutes quota details'
do
quota
=
subject
.
dig
(
:runners
,
:quota
)
expect
(
quota
).
to
be_present
expect
(
quota
.
fetch
(
:used
)).
to
eq
(
800
)
expect
(
quota
.
fetch
(
:limit
)).
to
eq
(
1000
)
end
end
context
'when namespace does not qualify for CI minutes'
do
before
do
allow
(
namespace
).
to
receive
(
:shared_runners_minutes_limit
).
and_return
(
0
)
end
it
'does not contain CI minutes quota details'
do
expect
(
subject
.
dig
(
:runners
,
:quota
)).
not_to
be_present
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment