Skip to content
Snippets Groups Projects
Commit c332b418 authored by Alessio Caiazza's avatar Alessio Caiazza
Browse files

Edit environments tier with API

Changelog: added
parent d1149340
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -251,6 +251,7 @@ POST /projects/:id/environments
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](index.md#namespaced-path-encoding) owned by the authenticated user |
| `name` | string | yes | The name of the environment |
| `external_url` | string | no | Place to link to for this environment |
| `tier` | string | no | The tier of the new environment. Allowed values are `production`, `staging`, `testing`, `development`, and `other` |
 
```shell
curl --data "name=deploy&external_url=https://deploy.gitlab.example.com" \
Loading
Loading
@@ -266,6 +267,7 @@ Example response:
"slug": "deploy",
"external_url": "https://deploy.gitlab.example.com",
"state": "available",
"tier": "production",
"created_at": "2019-05-25T18:55:13.252Z",
"updated_at": "2019-05-27T18:55:13.252Z"
}
Loading
Loading
@@ -287,6 +289,7 @@ PUT /projects/:id/environments/:environments_id
| `environment_id` | integer | yes | The ID of the environment |
| `name` | string | no | [Deprecated and will be removed in GitLab 15.0](https://gitlab.com/gitlab-org/gitlab/-/issues/338897) |
| `external_url` | string | no | The new `external_url` |
| `tier` | string | no | The tier of the new environment. Allowed values are `production`, `staging`, `testing`, `development`, and `other` |
 
```shell
curl --request PUT --data "name=staging&external_url=https://staging.gitlab.example.com" \
Loading
Loading
@@ -302,6 +305,7 @@ Example response:
"slug": "staging",
"external_url": "https://staging.gitlab.example.com",
"state": "available",
"tier": "staging",
"created_at": "2019-05-25T18:55:13.252Z",
"updated_at": "2019-05-27T18:55:13.252Z"
}
Loading
Loading
Loading
Loading
@@ -40,6 +40,7 @@ class Environments < ::API::Base
requires :name, type: String, desc: 'The name of the environment to be created'
optional :external_url, type: String, desc: 'URL on which this deployment is viewable'
optional :slug, absence: { message: "is automatically generated and cannot be changed" }
optional :tier, type: String, values: Environment.tiers.keys, desc: 'The tier of the environment to be created'
end
post ':id/environments' do
authorize! :create_environment, user_project
Loading
Loading
@@ -63,13 +64,14 @@ class Environments < ::API::Base
optional :name, type: String, desc: 'DEPRECATED: Renaming environment can lead to errors, this will be removed in 15.0'
optional :external_url, type: String, desc: 'The new URL on which this deployment is viewable'
optional :slug, absence: { message: "is automatically generated and cannot be changed" }
optional :tier, type: String, values: Environment.tiers.keys, desc: 'The tier of the environment to be created'
end
put ':id/environments/:environment_id' do
authorize! :update_environment, user_project
 
environment = user_project.environments.find(params[:environment_id])
 
update_params = declared_params(include_missing: false).extract!(:name, :external_url)
update_params = declared_params(include_missing: false).extract!(:name, :external_url, :tier)
if environment.update(update_params)
present environment, with: Entities::Environment, current_user: current_user
else
Loading
Loading
Loading
Loading
@@ -23,6 +23,7 @@
expect(json_response).to be_an Array
expect(json_response.size).to eq(1)
expect(json_response.first['name']).to eq(environment.name)
expect(json_response.first['tier']).to eq(environment.tier)
expect(json_response.first['external_url']).to eq(environment.external_url)
expect(json_response.first['project']).to match_schema('public_api/v4/project')
expect(json_response.first['enable_advanced_logs_querying']).to eq(false)
Loading
Loading
@@ -165,12 +166,13 @@
describe 'POST /projects/:id/environments' do
context 'as a member' do
it 'creates a environment with valid params' do
post api("/projects/#{project.id}/environments", user), params: { name: "mepmep" }
post api("/projects/#{project.id}/environments", user), params: { name: "mepmep", tier: 'staging' }
 
expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/environment')
expect(json_response['name']).to eq('mepmep')
expect(json_response['slug']).to eq('mepmep')
expect(json_response['tier']).to eq('staging')
expect(json_response['external']).to be nil
end
 
Loading
Loading
@@ -219,6 +221,15 @@
expect(json_response['external_url']).to eq(url)
end
 
it 'returns a 200 if tier is changed' do
put api("/projects/#{project.id}/environments/#{environment.id}", user),
params: { tier: 'production' }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/environment')
expect(json_response['tier']).to eq('production')
end
it "won't allow slug to be changed" do
slug = environment.slug
api_url = api("/projects/#{project.id}/environments/#{environment.id}", user)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment