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
1f3794ea
Commit
1f3794ea
authored
Sep 23, 2021
by
Allison Browne
Committed by
Fabio Pitino
Sep 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Quota Presenter to separate Quota related display logic
parent
7c2fbd9e
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
481 additions
and
394 deletions
+481
-394
ee/app/models/ci/minutes/quota.rb
ee/app/models/ci/minutes/quota.rb
+28
-79
ee/app/presenters/ci/minutes/quota_presenter.rb
ee/app/presenters/ci/minutes/quota_presenter.rb
+70
-0
ee/app/views/namespaces/_additional_minutes_status.html.haml
ee/app/views/namespaces/_additional_minutes_status.html.haml
+3
-2
ee/app/views/namespaces/_shared_runner_status.html.haml
ee/app/views/namespaces/_shared_runner_status.html.haml
+3
-2
ee/app/views/namespaces/pipelines_quota/_extra_shared_runners_minutes_quota.html.haml
...lines_quota/_extra_shared_runners_minutes_quota.html.haml
+5
-4
ee/app/views/namespaces/pipelines_quota/_list.haml
ee/app/views/namespaces/pipelines_quota/_list.haml
+8
-6
ee/spec/helpers/ee/namespaces_helper_spec.rb
ee/spec/helpers/ee/namespaces_helper_spec.rb
+5
-4
ee/spec/models/ci/minutes/quota_spec.rb
ee/spec/models/ci/minutes/quota_spec.rb
+46
-297
ee/spec/presenters/ci/minutes/quota_presenter_spec.rb
ee/spec/presenters/ci/minutes/quota_presenter_spec.rb
+313
-0
No files found.
ee/app/models/ci/minutes/quota.rb
View file @
1f3794ea
...
...
@@ -9,39 +9,14 @@ module Ci
class
Quota
include
Gitlab
::
Utils
::
StrongMemoize
Report
=
Struct
.
new
(
:used
,
:limit
,
:status
)
attr_reader
:namespace
def
initialize
(
namespace
)
@namespace
=
namespace
end
def
enabled?
namespace_root?
&&
total_minutes
.
nonzero?
end
# Status of the monthly allowance being used.
def
monthly_minutes_report
Report
.
new
(
monthly_minutes_used
,
minutes_limit
,
report_status
)
end
def
monthly_percent_used
return
0
unless
enabled?
return
0
if
monthly_minutes
==
0
100
*
monthly_minutes_used
.
to_i
/
monthly_minutes
end
# Status of any purchased minutes used.
def
purchased_minutes_report
status
=
purchased_minutes_used_up?
?
:over_quota
:
:under_quota
Report
.
new
(
purchased_minutes_used
,
purchased_minutes
,
status
)
end
def
purchased_percent_used
return
0
unless
enabled?
return
0
if
purchased_minutes
==
0
100
*
purchased_minutes_used
.
to_i
/
purchased_minutes
namespace_root?
&&
!
namespace_unlimited_minutes?
end
def
minutes_used_up?
...
...
@@ -58,14 +33,6 @@ module Ci
total_minutes
.
to_i
-
total_minutes_used
end
def
display_shared_runners_data?
namespace_root?
&&
any_project_enabled?
end
def
display_minutes_available_data?
display_shared_runners_data?
&&
total_minutes
.
nonzero?
end
def
total_minutes
strong_memoize
(
:total_minutes
)
do
monthly_minutes
+
purchased_minutes
...
...
@@ -78,54 +45,43 @@ module Ci
end
end
def
any_project_enabled?
strong_memoize
(
:
any_project_enabled
)
do
namespace
.
any_project_with_shared_runners_enabled?
def
purchased_minutes
strong_memoize
(
:
purchased_minutes
)
do
namespace
.
extra_shared_runners_minutes_limit
.
to_i
end
end
private
attr_reader
:namespace
def
minutes_limit
return
_
(
'Not supported'
)
unless
display_shared_runners_data?
if
display_minutes_available_data?
monthly_minutes
else
_
(
'Unlimited'
)
def
namespace_root?
strong_memoize
(
:namespace_root
)
do
namespace
.
root?
end
end
def
report_status
return
:disabled
unless
enabled?
monthly_minutes_used_up?
?
:over_quota
:
:under_quota
def
namespace_unlimited_minutes?
total_minutes
.
to_i
==
0
end
def
total_minutes_remaining
[
current_balance
,
0
].
max
def
monthly_minutes
strong_memoize
(
:monthly_minutes
)
do
(
namespace
.
shared_runners_minutes_limit
||
::
Gitlab
::
CurrentSettings
.
shared_runners_minutes
).
to_i
end
end
# === private to view ===
def
monthly_minutes_used_up?
return
false
unless
enabled?
monthly_minutes_used
>=
monthly_minutes
end
def
purchased_minutes_used_up?
return
false
unless
enabled?
any_minutes_purchased?
&&
purchased_minutes_used
>=
purchased_minutes
end
def
monthly_minutes_used
total_minutes_used
-
purchased_minutes_used
end
def
monthly_minutes_available?
total_minutes_used
<=
monthly_minutes
def
purchased_minutes_used_up?
return
false
unless
enabled?
any_minutes_purchased?
&&
purchased_minutes_used
>=
purchased_minutes
end
def
purchased_minutes_used
...
...
@@ -134,6 +90,12 @@ module Ci
total_minutes_used
-
monthly_minutes
end
private
def
monthly_minutes_available?
total_minutes_used
<=
monthly_minutes
end
def
no_minutes_purchased?
purchased_minutes
==
0
end
...
...
@@ -142,22 +104,9 @@ module Ci
purchased_minutes
>
0
end
def
monthly_minutes
strong_memoize
(
:monthly_minutes
)
do
(
namespace
.
shared_runners_minutes_limit
||
::
Gitlab
::
CurrentSettings
.
shared_runners_minutes
).
to_i
end
end
def
purchased_minutes
strong_memoize
(
:purchased_minutes
)
do
namespace
.
extra_shared_runners_minutes_limit
.
to_i
end
end
def
namespace_root?
strong_memoize
(
:namespace_root
)
do
namespace
.
root?
end
# === private to model ===
def
total_minutes_remaining
[
current_balance
,
0
].
max
end
end
end
...
...
ee/app/presenters/ci/minutes/quota_presenter.rb
0 → 100644
View file @
1f3794ea
# frozen_string_literal: true
module
Ci
module
Minutes
class
QuotaPresenter
<
Gitlab
::
View
::
Presenter
::
Simple
include
Gitlab
::
Utils
::
StrongMemoize
presents
Quota
,
as: :quota
Report
=
Struct
.
new
(
:used
,
:limit
,
:status
)
# Status of the monthly allowance being used.
def
monthly_minutes_report
Report
.
new
(
quota
.
monthly_minutes_used
,
minutes_limit
,
report_status
)
end
def
monthly_percent_used
return
0
unless
quota
.
enabled?
return
0
if
quota
.
monthly_minutes
==
0
100
*
quota
.
monthly_minutes_used
.
to_i
/
quota
.
monthly_minutes
end
# Status of any purchased minutes used.
def
purchased_minutes_report
status
=
quota
.
purchased_minutes_used_up?
?
:over_quota
:
:under_quota
Report
.
new
(
quota
.
purchased_minutes_used
,
quota
.
purchased_minutes
,
status
)
end
def
purchased_percent_used
return
0
unless
quota
.
enabled?
return
0
if
quota
.
purchased_minutes
==
0
100
*
quota
.
purchased_minutes_used
.
to_i
/
quota
.
purchased_minutes
end
def
display_minutes_available_data?
display_shared_runners_data?
&&
!
quota
.
namespace_unlimited_minutes?
end
def
display_shared_runners_data?
quota
.
namespace_root?
&&
any_project_enabled?
end
def
any_project_enabled?
strong_memoize
(
:any_project_enabled
)
do
quota
.
namespace
.
any_project_with_shared_runners_enabled?
end
end
private
def
report_status
return
:disabled
unless
quota
.
enabled?
quota
.
monthly_minutes_used_up?
?
:over_quota
:
:under_quota
end
def
minutes_limit
return
_
(
'Not supported'
)
unless
display_shared_runners_data?
if
display_minutes_available_data?
quota
.
monthly_minutes
else
_
(
'Unlimited'
)
end
end
end
end
end
ee/app/views/namespaces/_additional_minutes_status.html.haml
View file @
1f3794ea
...
...
@@ -2,11 +2,12 @@
-
namespace
=
local_assigns
.
fetch
(
:namespace
)
-
minutes_quota
=
namespace
.
ci_minutes_quota
-
minutes_quota_presenter
=
Ci
::
Minutes
::
QuotaPresenter
.
new
(
minutes_quota
)
-
return
unless
minutes_quota
.
enabled?
-
if
minutes_quota
.
display_shared_runners_data?
-
if
minutes_quota
_presenter
.
display_shared_runners_data?
%li
%span
.light
=
_
(
'Additional minutes:'
)
%strong
=
ci_minutes_report
(
minutes_quota
.
purchased_minutes_report
)
=
ci_minutes_report
(
minutes_quota
_presenter
.
purchased_minutes_report
)
ee/app/views/namespaces/_shared_runner_status.html.haml
View file @
1f3794ea
-
namespace
=
local_assigns
.
fetch
(
:namespace
)
-
minutes_quota
=
namespace
.
ci_minutes_quota
-
minutes_quota_presenter
=
Ci
::
Minutes
::
QuotaPresenter
.
new
(
minutes_quota
)
-
if
minutes_quota
.
display_shared_runners_data?
-
if
minutes_quota
_presenter
.
display_shared_runners_data?
%li
%span
.light
=
_
(
'Pipeline minutes quota:'
)
%strong
=
ci_minutes_report
(
minutes_quota
.
monthly_minutes_report
)
=
ci_minutes_report
(
minutes_quota
_presenter
.
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'
ee/app/views/namespaces/pipelines_quota/_extra_shared_runners_minutes_quota.html.haml
View file @
1f3794ea
-
return
unless
Gitlab
.
com?
-
minutes_quota
=
namespace
.
ci_minutes_quota
-
return
unless
minutes_quota
.
display_minutes_available_data?
&&
minutes_quota
.
purchased_minutes_report
.
limit
>
0
-
minutes_quota_presenter
=
Ci
::
Minutes
::
QuotaPresenter
.
new
(
minutes_quota
)
-
return
unless
minutes_quota_presenter
.
display_minutes_available_data?
&&
minutes_quota_presenter
.
purchased_minutes_report
.
limit
>
0
.row
.col-sm-6
%strong
=
_
(
"Additional minutes"
)
%div
=
ci_minutes_report
(
minutes_quota
.
purchased_minutes_report
)
=
ci_minutes_report
(
minutes_quota
_presenter
.
purchased_minutes_report
)
minutes
=
link_to
sprite_icon
(
'question-o'
),
help_page_path
(
'subscriptions/gitlab_com/index'
,
anchor:
'purchase-additional-ci-minutes'
),
target:
'_blank'
,
rel:
'noopener noreferrer'
.col-sm-6.right
#{
minutes_quota
.
purchased_percent_used
}
% used
=
ci_minutes_progress_bar
(
minutes_quota
.
purchased_percent_used
)
#{
minutes_quota
_presenter
.
purchased_percent_used
}
% used
=
ci_minutes_progress_bar
(
minutes_quota
_presenter
.
purchased_percent_used
)
ee/app/views/namespaces/pipelines_quota/_list.haml
View file @
1f3794ea
-
namespace
=
locals
.
fetch
(
:namespace
)
-
projects
=
locals
.
fetch
(
:projects
)
-
minutes_quota
=
namespace
.
ci_minutes_quota
-
minutes_quota_presenter
=
Ci
::
Minutes
::
QuotaPresenter
.
new
(
minutes_quota
)
.pipeline-quota.container-fluid
.row
...
...
@@ -21,19 +23,19 @@
-
else
=
s_
(
'UsageQuota|Current period usage'
)
%div
=
ci_minutes_report
(
minutes_quota
.
monthly_minutes_report
)
=
ci_minutes_report
(
minutes_quota
_presenter
.
monthly_minutes_report
)
minutes
=
link_to
sprite_icon
(
'question-o'
),
help_page_path
(
'user/admin_area/settings/continuous_integration'
,
anchor:
'shared-runners-pipeline-minutes-quota'
),
target:
'_blank'
,
'aria-label'
:
_
(
'Shared runners help link'
)
.col-sm-6.right
-
if
minutes_quota
.
display_minutes_available_data?
#{
minutes_quota
.
monthly_percent_used
}
% used
-
elsif
!
minutes_quota
.
any_project_enabled?
-
if
minutes_quota
_presenter
.
display_minutes_available_data?
#{
minutes_quota
_presenter
.
monthly_percent_used
}
% used
-
elsif
!
minutes_quota
_presenter
.
any_project_enabled?
0% used
-
else
=
s_
(
'UsageQuota|Unlimited'
)
=
ci_minutes_progress_bar
(
minutes_quota
.
monthly_percent_used
)
=
ci_minutes_progress_bar
(
minutes_quota
_presenter
.
monthly_percent_used
)
=
render
'namespaces/pipelines_quota/extra_shared_runners_minutes_quota'
,
namespace:
namespace
...
...
@@ -48,7 +50,7 @@
=
_
(
'Minutes'
)
%tbody
-
if
!
minutes_quota
.
any_project_enabled?
-
if
!
minutes_quota
_presenter
.
any_project_enabled?
%tr
%td
{
colspan:
2
}
.nothing-here-block
...
...
ee/spec/helpers/ee/namespaces_helper_spec.rb
View file @
1f3794ea
...
...
@@ -51,9 +51,10 @@ RSpec.describe EE::NamespacesHelper do
describe
'#ci_minutes_report'
do
let
(
:quota
)
{
Ci
::
Minutes
::
Quota
.
new
(
user_group
)
}
let
(
:quota_presenter
)
{
Ci
::
Minutes
::
QuotaPresenter
.
new
(
quota
)
}
describe
'rendering monthly minutes report'
do
let
(
:report
)
{
quota
.
monthly_minutes_report
}
let
(
:report
)
{
quota
_presenter
.
monthly_minutes_report
}
context
"when ci minutes quota is not enabled"
do
before
do
...
...
@@ -62,7 +63,7 @@ RSpec.describe EE::NamespacesHelper do
context
'and the namespace is eligible for unlimited'
do
before
do
allow
(
quota
).
to
receive
(
:namespace_
eligible
?
).
and_return
(
true
)
allow
(
quota
).
to
receive
(
:namespace_
root
?
).
and_return
(
true
)
allow
(
user_group
).
to
receive
(
:any_project_with_shared_runners_enabled?
).
and_return
(
true
)
end
...
...
@@ -79,7 +80,7 @@ RSpec.describe EE::NamespacesHelper do
context
'and the namespace is not eligible for unlimited'
do
before
do
allow
(
quota
).
to
receive
(
:namespace_
eligible
?
).
and_return
(
false
)
allow
(
quota
).
to
receive
(
:namespace_
root
?
).
and_return
(
false
)
end
it
'returns Not supported for the limit section'
do
...
...
@@ -103,7 +104,7 @@ RSpec.describe EE::NamespacesHelper do
end
describe
'rendering purchased minutes report'
do
let
(
:report
)
{
quota
.
purchased_minutes_report
}
let
(
:report
)
{
Ci
::
Minutes
::
QuotaPresenter
.
new
(
quota
)
.
purchased_minutes_report
}
context
'when extra minutes are assigned'
do
it
'returns the proper values for used and limit sections'
do
...
...
ee/spec/models/ci/minutes/quota_spec.rb
View file @
1f3794ea
This diff is collapsed.
Click to expand it.
ee/spec/presenters/ci/minutes/quota_presenter_spec.rb
0 → 100644
View file @
1f3794ea
This diff is collapsed.
Click to expand it.
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