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
22cff155
Commit
22cff155
authored
Nov 08, 2021
by
Kamil Trzciński
Committed by
Dylan Griffith
Nov 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make `/features` API accept percentage as float to enable 0.01%
parent
f02c40eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
+37
-2
lib/api/features.rb
lib/api/features.rb
+7
-2
spec/requests/api/features_spec.rb
spec/requests/api/features_spec.rb
+30
-0
No files found.
lib/api/features.rb
View file @
22cff155
...
...
@@ -14,7 +14,12 @@ module API
when
'0'
,
'false'
false
else
params
[
:value
].
to_i
# https://github.com/jnunemaker/flipper/blob/master/lib/flipper/typecast.rb#L47
if
params
[
:value
].
to_s
.
include?
(
'.'
)
params
[
:value
].
to_f
else
params
[
:value
].
to_i
end
end
end
...
...
@@ -59,7 +64,7 @@ module API
success
Entities
::
Feature
end
params
do
requires
:value
,
type:
String
,
desc:
'`true` or `false` to enable/disable, a
n integer
for percentage of time'
requires
:value
,
type:
String
,
desc:
'`true` or `false` to enable/disable, a
float
for percentage of time'
optional
:key
,
type:
String
,
desc:
'`percentage_of_actors` or the default `percentage_of_time`'
optional
:feature_group
,
type:
String
,
desc:
'A Feature group name'
optional
:user
,
type:
String
,
desc:
'A GitLab username'
...
...
spec/requests/api/features_spec.rb
View file @
22cff155
...
...
@@ -256,6 +256,21 @@ RSpec.describe API::Features, stub_feature_flags: false do
)
end
it
'creates a feature with the given percentage of time if passed a float'
do
post
api
(
"/features/
#{
feature_name
}
"
,
admin
),
params:
{
value:
'0.01'
}
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
json_response
).
to
match
(
'name'
=>
feature_name
,
'state'
=>
'conditional'
,
'gates'
=>
[
{
'key'
=>
'boolean'
,
'value'
=>
false
},
{
'key'
=>
'percentage_of_time'
,
'value'
=>
0.01
}
],
'definition'
=>
known_feature_flag_definition_hash
)
end
it
'creates a feature with the given percentage of actors if passed an integer'
do
post
api
(
"/features/
#{
feature_name
}
"
,
admin
),
params:
{
value:
'50'
,
key:
'percentage_of_actors'
}
...
...
@@ -270,6 +285,21 @@ RSpec.describe API::Features, stub_feature_flags: false do
'definition'
=>
known_feature_flag_definition_hash
)
end
it
'creates a feature with the given percentage of actors if passed a float'
do
post
api
(
"/features/
#{
feature_name
}
"
,
admin
),
params:
{
value:
'0.01'
,
key:
'percentage_of_actors'
}
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
json_response
).
to
match
(
'name'
=>
feature_name
,
'state'
=>
'conditional'
,
'gates'
=>
[
{
'key'
=>
'boolean'
,
'value'
=>
false
},
{
'key'
=>
'percentage_of_actors'
,
'value'
=>
0.01
}
],
'definition'
=>
known_feature_flag_definition_hash
)
end
end
context
'when the feature exists'
do
...
...
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