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
06165c47
Commit
06165c47
authored
Feb 19, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
a50a25e4
5ff775fd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
5 deletions
+53
-5
changelogs/unreleased/jej-feature-gates-can-be-set-by-group-path.yml
...unreleased/jej-feature-gates-can-be-set-by-group-path.yml
+5
-0
doc/api/features.md
doc/api/features.md
+2
-1
lib/api/features.rb
lib/api/features.rb
+1
-0
lib/feature.rb
lib/feature.rb
+8
-2
spec/lib/feature_spec.rb
spec/lib/feature_spec.rb
+3
-2
spec/requests/api/features_spec.rb
spec/requests/api/features_spec.rb
+34
-0
No files found.
changelogs/unreleased/jej-feature-gates-can-be-set-by-group-path.yml
0 → 100644
View file @
06165c47
---
title
:
Allow setting feature flags per GitLab group through the API
merge_request
:
25022
author
:
type
:
added
doc/api/features.md
View file @
06165c47
...
...
@@ -60,10 +60,11 @@ POST /features/:name
|
`value`
| integer/string | yes |
`true`
or
`false`
to enable/disable, or an integer for percentage of time |
|
`feature_group`
| string | no | A Feature group name |
|
`user`
| string | no | A GitLab username |
|
`group`
| string | no | A GitLab group's path, for example 'gitlab-org' |
|
`project`
| string | no | A projects path, for example 'gitlab-org/gitlab-ce' |
Note that you can enable or disable a feature for a
`feature_group`
, a
`user`
,
and a
`project`
in a single API call.
a
`group`
, a
nd a
`project`
in a single API call.
```
bash
curl
--data
"value=30"
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/features/new_library
...
...
lib/api/features.rb
View file @
06165c47
...
...
@@ -42,6 +42,7 @@ module API
requires
:value
,
type:
String
,
desc:
'`true` or `false` to enable/disable, an integer for percentage of time'
optional
:feature_group
,
type:
String
,
desc:
'A Feature group name'
optional
:user
,
type:
String
,
desc:
'A GitLab username'
optional
:group
,
type:
String
,
desc:
"A GitLab group's path, such as 'gitlab-org'"
optional
:project
,
type:
String
,
desc:
'A projects path, like gitlab-org/gitlab-ce'
end
post
':name'
do
...
...
lib/feature.rb
View file @
06165c47
...
...
@@ -113,11 +113,11 @@ class Feature
end
def
gate_specified?
%i(user project feature_group)
.
any?
{
|
key
|
params
.
key?
(
key
)
}
%i(user project
group
feature_group)
.
any?
{
|
key
|
params
.
key?
(
key
)
}
end
def
targets
[
feature_group
,
user
,
project
].
compact
[
feature_group
,
user
,
project
,
group
].
compact
end
private
...
...
@@ -141,5 +141,11 @@ class Feature
Project
.
find_by_full_path
(
params
[
:project
])
end
def
group
return
unless
params
.
key?
(
:group
)
Group
.
find_by_full_path
(
params
[
:group
])
end
end
end
spec/lib/feature_spec.rb
View file @
06165c47
...
...
@@ -186,13 +186,14 @@ describe Feature do
describe
Feature
::
Target
do
describe
'#targets'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:user_name
)
{
project
.
owner
.
username
}
subject
{
described_class
.
new
(
user:
user_name
,
project:
project
.
full_path
)
}
subject
{
described_class
.
new
(
user:
user_name
,
project:
project
.
full_path
,
group:
group
.
full_path
)
}
it
'returns all found targets'
do
expect
(
subject
.
targets
).
to
be_an
(
Array
)
expect
(
subject
.
targets
).
to
eq
([
project
.
owner
,
project
])
expect
(
subject
.
targets
).
to
eq
([
project
.
owner
,
project
,
group
])
end
end
end
...
...
spec/requests/api/features_spec.rb
View file @
06165c47
...
...
@@ -163,6 +163,40 @@ describe API::Features do
end
end
context
'when enabling for a group by path'
do
context
'when the group exists'
do
it
'sets the feature gate'
do
group
=
create
(
:group
)
post
api
(
"/features/
#{
feature_name
}
"
,
admin
),
params:
{
value:
'true'
,
group:
group
.
full_path
}
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
).
to
eq
(
'name'
=>
'my_feature'
,
'state'
=>
'conditional'
,
'gates'
=>
[
{
'key'
=>
'boolean'
,
'value'
=>
false
},
{
'key'
=>
'actors'
,
'value'
=>
[
"Group:
#{
group
.
id
}
"
]
}
])
end
end
context
'when the group does not exist'
do
it
'sets no new values and keeps the feature disabled'
do
post
api
(
"/features/
#{
feature_name
}
"
,
admin
),
params:
{
value:
'true'
,
group:
'not/a/group'
}
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
).
to
eq
(
"name"
=>
"my_feature"
,
"state"
=>
"off"
,
"gates"
=>
[
{
"key"
=>
"boolean"
,
"value"
=>
false
}
]
)
end
end
end
it
'creates a feature with the given percentage if passed an integer'
do
post
api
(
"/features/
#{
feature_name
}
"
,
admin
),
params:
{
value:
'50'
}
...
...
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