Commit 96ba4573 authored by Jason Goodman's avatar Jason Goodman Committed by Shinya Maeda

Support renaming a feature flag via the api

Update documentation and specs
parent 88b32d3c
...@@ -96,13 +96,13 @@ Example response: ...@@ -96,13 +96,13 @@ Example response:
Gets a single feature flag. Gets a single feature flag.
```plaintext ```plaintext
GET /projects/:id/feature_flags/:name GET /projects/:id/feature_flags/:feature_flag_name
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------| | ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding). | | `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding). |
| `name` | string | yes | The name of the feature flag. | | `feature_flag_name` | string | yes | The name of the feature flag. |
```shell ```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature
...@@ -201,15 +201,16 @@ Example response: ...@@ -201,15 +201,16 @@ Example response:
Updates a feature flag. Updates a feature flag.
```plaintext ```plaintext
PUT /projects/:id/feature_flags/:name PUT /projects/:id/feature_flags/:feature_flag_name
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------| | ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding). | | `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding). |
| `name` | string | yes | The name of the feature flag. | | `feature_flag_name` | string | yes | The current name of the feature flag. |
| `description` | string | no | The description of the feature flag. | | `description` | string | no | The description of the feature flag. |
| `active` | boolean | no | The active state of the flag. [Supported](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38350) in GitLab 13.3 and later. | | `active` | boolean | no | The active state of the flag. [Supported](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38350) in GitLab 13.3 and later. |
| `name` | string | no | The new name of the feature flag. [Supported](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38350) in GitLab 13.3 and later. |
| `strategies` | JSON | no | The feature flag [strategies](../operations/feature_flags.md#feature-flag-strategies). | | `strategies` | JSON | no | The feature flag [strategies](../operations/feature_flags.md#feature-flag-strategies). |
| `strategies:id` | JSON | no | The feature flag strategy id. | | `strategies:id` | JSON | no | The feature flag strategy id. |
| `strategies:name` | JSON | no | The strategy name. | | `strategies:name` | JSON | no | The strategy name. |
...@@ -275,13 +276,13 @@ Example response: ...@@ -275,13 +276,13 @@ Example response:
Deletes a feature flag. Deletes a feature flag.
```plaintext ```plaintext
DELETE /projects/:id/feature_flags/:name DELETE /projects/:id/feature_flags/:feature_flag_name
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------| | ------------------- | ---------------- | ---------- | ---------------------------------------------------------------------------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding). | | `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding). |
| `name` | string | yes | The name of the feature flag. | | `feature_flag_name` | string | yes | The name of the feature flag. |
```shell ```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" --request DELETE "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature" curl --header "PRIVATE-TOKEN: <your_access_token>" --request DELETE "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"
......
---
title: Support renaming feature flags via the api
merge_request: 38425
author:
type: fixed
...@@ -81,9 +81,9 @@ module API ...@@ -81,9 +81,9 @@ module API
end end
params do params do
requires :name, type: String, desc: 'The name of the feature flag' requires :feature_flag_name, type: String, desc: 'The name of the feature flag'
end end
resource 'feature_flags/:name', requirements: FEATURE_FLAG_ENDPOINT_REQUIREMENTS do resource 'feature_flags/:feature_flag_name', requirements: FEATURE_FLAG_ENDPOINT_REQUIREMENTS do
desc 'Get a feature flag of a project' do desc 'Get a feature flag of a project' do
detail 'This feature was introduced in GitLab 12.5' detail 'This feature was introduced in GitLab 12.5'
success EE::API::Entities::FeatureFlag success EE::API::Entities::FeatureFlag
...@@ -145,6 +145,7 @@ module API ...@@ -145,6 +145,7 @@ module API
success EE::API::Entities::FeatureFlag success EE::API::Entities::FeatureFlag
end end
params do params do
optional :name, type: String, desc: 'The name of the feature flag'
optional :description, type: String, desc: 'The description of the feature flag' optional :description, type: String, desc: 'The description of the feature flag'
optional :active, type: Boolean, desc: 'Active/inactive value of the flag' optional :active, type: Boolean, desc: 'Active/inactive value of the flag'
optional :strategies, type: Array do optional :strategies, type: Array do
...@@ -237,9 +238,9 @@ module API ...@@ -237,9 +238,9 @@ module API
def feature_flag def feature_flag
@feature_flag ||= if feature_flags_new_version_enabled? @feature_flag ||= if feature_flags_new_version_enabled?
user_project.operations_feature_flags.find_by_name!(params[:name]) user_project.operations_feature_flags.find_by_name!(params[:feature_flag_name])
else else
user_project.operations_feature_flags.legacy_flag.find_by_name!(params[:name]) user_project.operations_feature_flags.legacy_flag.find_by_name!(params[:feature_flag_name])
end end
end end
......
...@@ -814,6 +814,17 @@ RSpec.describe API::FeatureFlags do ...@@ -814,6 +814,17 @@ RSpec.describe API::FeatureFlags do
expect(feature_flag.reload.active).to eq(false) expect(feature_flag.reload.active).to eq(false)
end end
it 'updates the feature flag name' do
params = { name: 'new-name' }
put api("/projects/#{project.id}/feature_flags/feature1", user), params: params
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/feature_flag', dir: 'ee')
expect(json_response['name']).to eq('new-name')
expect(feature_flag.reload.name).to eq('new-name')
end
it 'ignores a provided version parameter' do it 'ignores a provided version parameter' do
params = { description: 'other description', version: 'bad_value' } params = { description: 'other description', version: 'bad_value' }
......
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